Suppress duplicate notifications

Asked by Paul W

Hi,

New to MQTT so apologies if this is a daft question.

If I publish to topic room/temperature a value of 20, a message gets sent to all subscribers. Great!

If I publish the same value of 20 to the same topic then subscribers get notified again. Is there a combination of flags that will stop a notification being sent if the new published value is the same as the existing value?

Paul

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

Hi Paul,

Sorry, this isn't possible with the current code and would break the MQTT spec as far as I see it. You'd have to implement this in your publishing client.

If you were absolutely desperate to have this functionality in the broker, applying the below patch to src/subs.c from version 1.1 should work for retained messages only (I've not tested it though):

diff -r 1b8e749fe194 src/subs.c
--- a/src/subs.c Thu Dec 20 15:10:39 2012 +0000
+++ b/src/subs.c Fri Dec 21 22:43:57 2012 +0000
@@ -81,6 +81,7 @@
        uint16_t mid;
        struct _mosquitto_subleaf *leaf;
        bool client_retain;
+ bool duplicate = false;

        leaf = hier->subs;

@@ -96,6 +97,12 @@
                        hier->retained->ref_count--;
                        /* FIXME - it would be nice to be able to remove the message from the store at this point if ref_count == 0 */
                        db->retained_count--;
+
+ if(hier->retained->msg.payloadlen == stored->msg.payloadlen){
+ if(!memcmp(hier->retained->msg.payload, stored->msg.payload, stored->msg.payloadlen)){
+ duplicate = true;
+ }
+ }
                }
                if(stored->msg.payloadlen){
                        hier->retained = stored;
@@ -104,6 +111,9 @@
                }else{
                        hier->retained = NULL;
                }
+ if(duplicate){
+ return MOSQ_ERR_SUCCESS;
+ }
        }
        while(source_id && leaf){
                if(leaf->context->is_bridge && !strcmp(leaf->context->id, source_id)){

Can you help with this problem?

Provide an answer of your own, or ask Paul W for more information if necessary.

To post a message you must log in.