4

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

pah
  • 4,700
  • 6
  • 28
  • 37
rao
  • 323
  • 1
  • 3
  • 7

2 Answers2

19

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.

ralight
  • 11,033
  • 3
  • 49
  • 59
1

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.

金金庸
  • 21
  • 1
  • 4
    This is a question about queued messages for persistent subscriptions not retained messages, they are 2 very different things – hardillb Jan 30 '16 at 16:23
  • The retain flag is not meant to retain all the messages, but to retain the last message. So that subscribers have the last state of the sender when it subscribes to a particular topic – Riz Dec 16 '19 at 07:41