node.js - Mqtt - Use QoS 1 when … -


i'm following tutorial www.hivemq.com/mqtt-essentials-part-6-mqtt-quality-of-service-levels/ can't figure out implement

of course application must tolerating duplicates , process them accordingly.

can give me simple example, please ?

for instance i've (i set deploy following https://medium.com/@lelylan/how-to-build-an-high-availability-mqtt-cluster-for-the-internet-of-things-8011a06bd000)

module.exports.authorizepublish = function(client, topic, payload, callback) {     var chunks = topic.split('/');     if(chunks.length === 4) {         debug('authorizing subscribe', client.device_id == chunks[1]);         debug('nickname', chunks[1]);         debug('channel', chunks[3]);         debug('topic', chunks[2]);         debug('payload', payload.tostring('utf8'));          var data = {             devicenickname:chunks[1],             channel:chunks[3],             topic:chunks[2],             payload:payload.tostring('utf8')         };         message.insert(data, function (err, message) {                 if (err){                     debug(err);                     return;                 }                 debug(message);         });     }     callback(null, client.device_id === chunks[1]); } 

i'm still rather learner of mqtt expert, understanding of handling of duplicate messages qos 1 following:

suppose have application whatever reason needs count messages received broker. however, don't want take duplicate messages (sent when client didn't ack message in time) taken account.

i use java paho client, code be:

int counter = 0; public void messagearrived(string topic, mqttmessage message) throws mqttexception {    if (message.isduplicate() == false) {       counter++;    } } 

Comments