Receive offline messages mqtt

穿精又带淫゛_ 提交于 2020-01-01 03:43:06

问题


I'm using mosquitto as broker and paho(python) as client. I'm trying to make subscriber to receive offline messages.

For that I made following changes:

  • Fixed client ID
  • qos level 2

but, still the subscriber is not able to receive messages.

any help?

Thanks, Rahul


回答1:


In order to have your client as a durable client and receive messages that were sent to topics when it was offline, you need to meet the following criteria:

  1. Fixed client ID (as you've done)
  2. Always connect with clean_session=False
  3. Subscriptions must be made with QoS>0
  4. Messages published must have QoS>0

The mistake that I make most frequently is to forget either one of points 3 and 4, so I'm publishing with QoS=0 or subscribing with QoS=0, either of which would cause messages not to be stored.

You could also look at the queue_qos0_messages option to tell the broker to store QoS=0 messages as well. Note that this is an implementation detail that may be specific to mosquitto.




回答2:


Check if you have set the retain flag to true when publishing message to topic, with retain=true, new connected client which subscribes the topic will receive the retained message.



来源:https://stackoverflow.com/questions/34150452/receive-offline-messages-mqtt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!