mqttspring-integration-mqtt

MQTT - how to prevent yourself from receiving your very own published message?


Okay, this may be a really stupid question but here's the deal. My IoT device is subscribed to topic "Weather/Humidity". The device publishes real time humidity data to the broker. No problem there. Thing is, it also receives other devices which publishes humidity data, still no problem. But every time the device publishes the data, it gets a loop-back/echo from the broker, with the exact same message it just published.

I understand this is actually how things are supposed to work but is there any non-hassle way to filter out the device's own message it just published?

So far the scheme I thought of is that the published messages features an "ID" section. So if it's its own ID, it ignores it; if it's from other publishers, it heeds the message.

I couldn't help but suspect their are better, more clever ways to go about doing this.

Please help, thanks in advance.


Solution

  • You have 3 choices

    1. Just don't have the device subscribe to the same topic that it publishes on
    2. Include the ID as already mentioned
    3. Move to MQTT v5 which has a specific flag that can be set at subscription time that tells the broker not to send messages that originated at the subscriber.

    Option 3 requires both a broker and a client library that supports MQTTv5