JohnL
JohnL

Reputation: 14106

With Mosquitto broker, how to subscribe to a topic and get any message just once

This is newbie question I'm sure, but using Mosquitto how do I subscribe to a retained message and guarantee that I only get the message once? I have a Paho based java subscriber, and in testing what I notice is, if my subscriber is brought down, and then restarted it pulls some of the same messages that it received before it came down. (Normally it would stay up forever, but stuff happens.) And it's critical the subscriber get each message only once. (For my use case there is only 1 subscriber.)

Is there something built into Mosquitto that provides this mechanism or is this something I have to build into my data schema and retrieval process?

I see there is a way of deleting a message by topic (https://lists.launchpad.net/mosquitto-users/msg00067.html) but right now my topics are pretty generic [Company]/[MAC address]/[Topic x] and it's possible to have two separate messages on the queue with the same topic, and I'm assuming if I send an empty message to a given topic I'll end up deleting all messages of said topic.

Thanks in advance for any help on this.

Upvotes: 0

Views: 703

Answers (1)

Noor
Noor

Reputation: 41

set the QoS level as 2.

QoS-level-2: Exactly-once delivery. This is the highest level that also incurs most over head interms of control messages and the need for locally storing the messages. Exactly-once is a combination of at-least-once and at-most-once delivery guarantee.

Upvotes: 1

Related Questions