Prabjot Singh
Prabjot Singh

Reputation: 4767

Messages not received on first time connection

I am unable to receive messages on first time connection. for in more detail,user A is connected and publishing messages,but user B is not connected to that topic.So when user B will connect,he will not get any message from user A because there is first time connection b/w user a and user b.

How we can resolve this issue ?

Thanks

Upvotes: 0

Views: 532

Answers (1)

ralight
ralight

Reputation: 11608

A principle of pub/sub is that the publisher and subscriber are decoupled, so you shouldn't really be thinking in terms of user a being connected to user b.

If you want a client to receive messages when they are not connected (leaving retained messages to one side), the only way to do this is:

  • Connect beforehand with cleansession=false
  • Subscribe with QoS>0 (or on mosquitto use the queue_qos0_messages option)
  • Ensure that messages are published with QoS>0
  • When the client reconnects, use cleansession=false

To test this, try:

mosquitto_sub -i prajbot-singh -h test.mosquitto.org -t prajbot-singh -c -q 1

Then quit from mosquitto_sub and run:

mosquitto_pub -h test.mosquitto.org -t prajbot-singh -m hello -q 1

And run mosquitto_sub again:

mosquitto_sub -i prajbot-singh -h test.mosquitto.org -t prajbot-singh -c -q 1

Upvotes: 1

Related Questions