My understanding was that the callbacks queued but since I was not 100% certain I wrote a pair of scripts to test the behavior.
First the subscription and callbacks:
import paho.mqtt.client as mqtt
from time import sleep
def on_connect(client, userdata, flags, rc):
client.subscribe('callback-test/#')
def test1(client, userdata, message):
print("Test1 start")
sleep(2)
print("Test1 done")
def test2(client, userdata, message):
print("Test2 start")
sleep(2)
print("Test2 done")
def on_log(client, userdata, level, buf):
print(level, buf)
client = mqtt.Client()
client.on_connect = on_connect
client.message_callback_add('callback-test/1', test1)
client.message_callback_add('callback-test/2', test2)
client.on_log = on_log
client.connect("test.mosquitto.org")
client.loop_forever()
And here is the script to send messages to trigger those callbacks:
import paho.mqtt.client as mqtt
# noinspection PyShadowingNames,PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
def on_connect(client, userdata, flags, rc):
client.publish('callback-test/1', "test1")
client.publish('callback-test/2', "test2")
# noinspection PyShadowingNames,PyUnusedLocal,PyUnusedLocal
def on_log(client, userdata, level, buf):
print(level, buf)
client = mqtt.Client()
client.on_connect = on_connect
client.on_log = on_log
client.connect("test.mosquitto.org")
client.loop_forever()
When you run both scripts the first one returns:
Test1 start
Test1 done
Test2 start
Test2 done
From this test I feel pretty confident that it is automatically queuing the callbacks.