eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.1k stars 2.4k forks source link

libmosquitto Old Messages Are Retained #1762

Open apaly opened 4 years ago

apaly commented 4 years ago

Hello, I am having a big problem getting new messages using libmosquitto. The scenario is:

  1. There two clients (A and B) based on libmosquitto with a C++ application.
  2. They are both publishers and subscribers.
  3. A reads data often from B.
  4. Once A connects it only gets the old message from B.
  5. I checked with mosquitto_sub and it always gets the new messages from B.
  6. I have used the settings MQTT_SUB_OPT_SEND_RETAIN_NEVER and MQTT_SUB_OPT_SEND_RETAIN_NEW but no success.
  7. I have also used mosquitto_subscribe_v5, mosquitto_subscribe and mosquitto_subscribe_multiple but no success either.

Can you provide help on what I am missing.

Thanks

ralight commented 4 years ago

It's a bit difficult to say what is going on here without more details, but common problems include only sending a SUBSCRIBE when you first start the application - instead send it in the on_connect callback. Also make sure you are not using the same client id for both clients, and that you are using one of mosquitto_loop_start() and mosquitto_loop_forever().

If that doesn't help, you will need to provide a simplified version of your client so we can see what the details are.

apaly commented 4 years ago

Thanks for your reply.

After further check I realised that the messages from client B eventually gets to A, but it takes time from about 30 seconds. I tried your suggestions but the situation remains the same.

A simplified version of my client would be a bit difficult for me to provide because of the nature of my program.

ralight commented 4 years ago

Sorry, without some idea of what you are doing it's going to be extremely difficult to offer you any more suggestions.

ralight commented 4 years ago

Could you try and make a simple client that did the same subscribe flow but without the main part of your application instead?