You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation, you mention it is possible to re-use Client in several tasks. However, it is only usable for tasks that actually only publish messages. I would like to be able to write an application which shares Client instance in several independent tasks (let's call them "modules") with complete MQTT functionality: each task would subscribe for its own topics and receive only message for them. Right now, I have to make all the subscriptions and reception in a single task, so I have to manually mix functionality/logic from all the "modules". And the logic is not about subscribing and receiving messages only, because you also need the outer reconnection loop and after connecting back to the broker, you do not usually only re-subscribe, but also publish some messages to initiate communication with other MQTT clients (to confirm their state after broker reconnection etc.).
Instead of mixing modules, I would recommend the async Client context manager to not return itself, but some more specific instance, which would store internally its subscriptions and fetch messages from the global client queue according to them (the messages would be possibly also copied if multiple modules subscribe for the same topic).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In the documentation, you mention it is possible to re-use Client in several tasks. However, it is only usable for tasks that actually only publish messages. I would like to be able to write an application which shares Client instance in several independent tasks (let's call them "modules") with complete MQTT functionality: each task would subscribe for its own topics and receive only message for them. Right now, I have to make all the subscriptions and reception in a single task, so I have to manually mix functionality/logic from all the "modules". And the logic is not about subscribing and receiving messages only, because you also need the outer reconnection loop and after connecting back to the broker, you do not usually only re-subscribe, but also publish some messages to initiate communication with other MQTT clients (to confirm their state after broker reconnection etc.).
Instead of mixing modules, I would recommend the async Client context manager to not return itself, but some more specific instance, which would store internally its subscriptions and fetch messages from the global client queue according to them (the messages would be possibly also copied if multiple modules subscribe for the same topic).
So, instead of:
do
or, to preserve both old (global) and new (module specific) functionality:
Beta Was this translation helpful? Give feedback.
All reactions