1
votes

I have issue when using npm mqtt with nodejs. Sever subscribe topic 'alert/userId' to receive data publish from client then server unsubscribe this topic . after each subscribe and unsubscribe message is duplicate. The client sends 1 message; the server receives more 1 message.

2
Please update the question with the publish and subscribe code to help us understand exactly what is happening herehardillb

2 Answers

0
votes

How did you publish the message? Did you set the retained flag to true?

If so this message will be delivered every time the client connects to the broker until it is cleared (by sending a null payload message to the same topic)

0
votes

Publishing with QoS 1 means the message will be delivered at least once. Any subscribers could then receive the same message more than once.

You probably want to use QoS 2 if you want the message to be delivered exactly once.