MQTT Async Worker

239 views
Skip to first unread message

Vito R

unread,
Oct 13, 2015, 2:34:49 PM10/13/15
to MQTT
Best regards

I am implementing a MQTT worker in python with paho-mqtt.

MQTT Client (Worker)   <------->   Mosquitto Broker  <------->  Very Many MQTT Clients (if we're lucky!)

The worker is subscribed to "topic"                                              All clients published in "topic".

I need "on_message" is asynchronous. is not blocked while processing a message.

Are all the on_message() multi threaded in different threads, so that if one of the task is time consuming, other messages can still be processed? If not, how can I achieve this behaviour?


Roger Light

unread,
Oct 14, 2015, 5:51:18 PM10/14/15
to mq...@googlegroups.com
Hi Vito,

The on_message() call will block until it has finished. I imagine you
could use a local queue to do the processing to alleviate this
problem.

Cheers,

Roger
> --
> To learn more about MQTT please visit http://mqtt.org
> ---
> You received this message because you are subscribed to the Google Groups
> "MQTT" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mqtt+uns...@googlegroups.com.
> To post to this group, send email to mq...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mqtt.
> For more options, visit https://groups.google.com/d/optout.

Vito R

unread,
Oct 15, 2015, 6:14:00 PM10/15/15
to MQTT, ro...@atchoo.org
Thank you very much for the reply.

Then, that the difference between:

mosquitto_connect
mosquitto_connect_async

I thought that the second would help me in my problem, after trying it, I realized it does not. I do not understand why. What is the difference between them?

Roger Light

unread,
Oct 17, 2015, 3:46:02 PM10/17/15
to mq...@googlegroups.com
Hi Vito,

This discussion should reallly be on the mosquitto mailing list - if
you have any more related questions please take them there.

mosquitto_connect() blocks until the socket connection completes,
mosquitto_connect_async() does not.

Cheers,

Roger

Vito R

unread,
Oct 18, 2015, 7:10:23 PM10/18/15
to MQTT, ro...@atchoo.org
Sorry, an error was caused by copying and pasting quickly. from the wrong source.
I meant to say:

mqttc = mqtt.Client()
mqttc.connect(...)
mqttc.connect_async(...)

Thanks for the reply. and from now on I will refer to everything related to mosquitto:
Reply all
Reply to author
Forward
0 new messages