Saturday 18 March 2017

node.js + mosca + mqtt unable to prevent notifying subscribers on publish to topic

I am using mosca/MQTT Broker in a node.js application. I have a Topic defined like if_published_5_Times, where in when the publisher publishes some data 5 times/threshold, data has to be sent to the subscribers of that topic.

code: function socket_handler(socket, mqtt) { // This code is inside socket & mosca informs the subscriber every time anything publihed // Called when a client publishes data mqtt.on('published', (data, client) => { if (!client) return;

    socket.emit('debug', {
        type: 'PUBLISH', 
        msg: 'Client "' + client.id + '" published "' + JSON.stringify(data) + '"'
    });
});

// Called when a client subscribes
mqtt.on('subscribed', (topic, client) => {
    if (!client) return;

    socket.emit('debug', {
        type: 'SUBSCRIBE',
        msg: 'Client "' + client.id + '" subscribed to "' + topic + '"'
    });
});}

Problem 1: Unable to check for mongodb collection on local made by mosca. How to view it? Can I add new fields to it?

Problem 2: How to keep count and prevent subscriber to be notified if threshhold not reached in mosca. eg. If threshold is set to 5, notify subscribers only if data published 5 times on the topic.



via user1179299

No comments:

Post a Comment