Router for mqtt subscriptions.
This module a router for use with MQTT subscriptions.
npm install mqtt-router
If you have just started with MQTT the first thing you will notice is there is only callback registered for on Message, even though you can register multiple subscriptions.. It is therefore up to you the developer to route these to the correct handler, which is why I wrote this library.
I have added a simple override for the topic subscription to enable named params, really this is to avoid the inevitable tokenising of the topic which I do every time I build complex topic structures.
NOTE: I will need to revisit this with some more validation, but for now it works for my simple requirements.
var mqtt = require'mqtt'mqttrouter = require'mqtt-router';var settings =reconnectPeriod: 5000;// client connectionvar client = mqttconnect'mqtt://localhost' settings;// enable the subscription routervar router = mqttrouterwrapclient;// subscribe to messages for 'hello/me'routersubscribe'hello/me'console.log'received' topic message;;// subscribe to messages for 'hello/you'routersubscribe'hello/you'console.log'received' topic message;;// subscribe to messages for 'some/+/you' with a named param for that tokenroutersubscribe'some/+:person/you'console.log'received' topic message;;
One thing to note is that subscriptions are refreshed on reconnect, the status of the connection is also
exposed via the
Copyright (c) 2013 Mark Wolfe Licensed under the MIT license.