wialon / gmqtt

Python MQTT v5.0 async client
MIT License
385 stars 53 forks source link

Handler does not work for null body retained messages published before the handler created #127

Closed freemansgit closed 3 years ago

freemansgit commented 3 years ago

Handler does not work for null body retained messages published before the handler created. One service publishes null body messages with retaining True. Another service started later and its handlers don't react only on null-body retained messages. With other kinds of messages, everything is ok and Handlers catch it successfully. Maybe I should add some specific parameters for that case?

hidaris commented 3 years ago

It seems that the broker sent the client a retain message before your subscription took effect, did you use the subscription in the on connect callback? I'm wondering if gmqtt can ensure that the subscriptions take effect even when connecting.

freemansgit commented 3 years ago

Yes, we use the subscription in the on_connect callback. We found one interesting info https://community.openhab.org/t/clearing-mqtt-retained-messages/58221 that article says the approach to drop retain message is to send null message to the topic. Our filters wait 'retain' messages and did not react on not 'retain' messages. Maybe this is the answer.

Lenka42 commented 3 years ago

@freemansgit hi, subscription has retain_as_published flag, by default it is False. So by default, when publisher publishes message with retain True and the listener is online, listener will get the message with retain False flag. Listener will receive retain True messages only immediately after subscription, these messages are from broker storage.

freemansgit commented 3 years ago

This flag did not help, We think that it is mqtt specific point. That retain flag drops if the null message is posted before subscription of the another client

Lenka42 commented 3 years ago

@freemansgit if client subscribes after null retain message is published, it will not get any message from this topic at all. Null message removes retain message in the topic.

freemansgit commented 3 years ago

Thanks for the quick support. I close the issue