# Core Mqtt Agent API callbacks

**URL:** <https://forums.freertos.org/t/core-mqtt-agent-api-callbacks/14403>\
**Category:** Libraries\
**Created:** [February 7, 2022, 1:22pm UTC](https://forums.freertos.org/t/core-mqtt-agent-api-callbacks/14403 "2022-02-07T13:22:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Litan](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Litan](https://forums.freertos.org/u/Litan)\
**Post date:** [February 7, 2022, 1:22pm UTC](https://forums.freertos.org/t/core-mqtt-agent-api-callbacks/14403/1 "2022-02-07T13:22:07Z")

</div>

Hi,

I’m working in an IoT project where I’m trying to use the MQTT Agent library for the first time. I’ve got some user app tasks running in a main thread and the MqttAgent running in another thread.

Reading the library functions I can see that the user App can use the thread safe API functions to publish, subscribe,… passing a callback function in the command info arguments.

So if I got it right, these callback functions will be called from the MQTT\_Agent thread when the publish/subscribe command is completed, which means that are being executed from the Agent’s thread and will have the Agent’s task priority?

If I want to pass the data from the responses to the main user app (which is in different thread) should I use a queue from the callback to the user app main tasks or is there any better/smarter way do handle this?

My concern is that if I want for instance to execute a blocking piece of code in one of the callbacks that would prevent the MQTT Agent from handle its other commands. So should I treat the callbacks like a sort of ISR running only non blocking code?

Thanks,  
Diego B

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [February 7, 2022, 7:26pm UTC](https://forums.freertos.org/t/core-mqtt-agent-api-callbacks/14403/2 "2022-02-07T19:26:06Z")

</div>

> [@Litan](#):
>
> which means that are being executed from the Agent’s thread and will have the Agent’s task priority?

Yes, that is correct.

> [@Litan](#):
>
> If I want to pass the data from the responses to the main user app (which is in different thread) should I use a queue from the callback to the user app main tasks or is there any better/smarter way do handle this?

That is one way. You can also copy to a buffer (which can be dynamically allocated or you can maintain a static pool of buffer) and pass the pointer to that buffer using queue.

> [@Litan](#):
>
> So should I treat the callbacks like a sort of ISR running only non blocking code?

Correct.

Thanks.

---

<div class="post-metadata">

**Author:** ![Litan](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@Litan](https://forums.freertos.org/u/Litan)\
**Post date:** [February 8, 2022, 9:40am UTC](https://forums.freertos.org/t/core-mqtt-agent-api-callbacks/14403/3 "2022-02-08T09:40:20Z")

</div>

Hi Aggarg,

Thanks very much for clarifying that, it makes a lot of sense now.

Regards,  
Diego
