This module a router for use with MQTT subscriptions.
JavaScript
Latest commit 14ecc03 Apr 18, 2014 @wolfeidau 0.5.0
Permalink
Failed to load latest commit information.
examples Updated docs and added reconnect handling for subscriptions. Apr 18, 2014
lib Updated docs and added reconnect handling for subscriptions. Apr 18, 2014
test Changed tests to ensure there is some using $ in topic name. Apr 14, 2014
.gitignore Initial import. Sep 7, 2013
.jshintrc Initial import. Sep 7, 2013
LICENSE-MIT Initial import. Sep 7, 2013
Makefile Initial import. Sep 7, 2013
README.md Updated docs and added reconnect handling for subscriptions. Apr 18, 2014
index.js Initial import. Sep 7, 2013
package.json

README.md

mqtt-router Build Status

This module a router for use with MQTT subscriptions.

NPM NPM

Installation

npm install mqtt-router

TLDR

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.

usage

var mqtt = require('mqtt')
  , mqttrouter = require('mqtt-router');

var settings = {
  reconnectPeriod: 5000
};

// client connection
var client = mqtt.connect('mqtt://localhost', settings);

// enable the subscription router
var router = mqttrouter.wrap(client);

// subscribe to messages for 'hello/me'
router.subscribe('hello/me', function(topic, message){
  console.log('received', topic, message);
});

// subscribe to messages for 'hello/you'
router.subscribe('hello/you', function(topic, message){
  console.log('received', topic, message);
});

// subscribe to messages for 'some/+/you' with a named param for that token
router.subscribe('some/+:person/you', function(topic, message, params){
  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 isConnected method.

License

Copyright (c) 2013 Mark Wolfe Licensed under the MIT license.