Barebone MQTT server that can run on any stream server.
To install aedes, simply use npm:
npm install aedes --save
var aedes = require('./aedes')()
var server = require('net').createServer(aedes.handle)
var port = 1883
server.listen(port, function () {
console.log('server listening on port', port)
})
aedes()
instance.handle()
instance.subscribe()
instance.publish()
instance.unsubscribe()
instance.authenticate()
instance.authorizePublish()
instance.authorizeSubscribe()
instance.close()
Client
client.publish()
client.subscribe()
client.close()
Creates a new instance of Aedes.
Options:
mq
: an instance of MQEmitter.concurrency
: the max number of messages delivered concurrently, defaults to100
.heartbeatInterval
: the interval at which the broker heartbeat is emitted, it used by other broker in the cluster, the default is60000
milliseconds.connectTimeout
: the max number of milliseconds to wait for the CONNECT packet to arrive, defaults to30000
milliseconds.
Events:
Handle the given duplex as a MQTT connection.
var aedes = require('./aedes')()
var server = require('net').createServer(aedes.handle)
After done
is called, every time publish is invoked on the
instance (and on any other connected instances) with a matching topic
the func
function will be called. It also support retained messages lookup.
func
needs to call cb
after receiving the message.
It supports backpressure.
Publish the given packet to subscribed clients and functions. A packet must be valid for mqtt-packet.
It supports backpressure.
The reverse of subscribe.
It will be called when a new client connects. Ovverride to supply custom authentication logic.
instance.authenticate = function (client, username, password, callback) {
callback(null, username === 'matteo')
}
It will be called when a client publishes a message. Ovverride to supply custom authorization logic.
instance.authorizePublish = function (client, packet, callback) {
if (packet.topic === 'aaaa') {
return callback(new Error('wrong topic'))
}
if (packet.topic === 'bbb') {
packet.payload = new Buffer('overwrite packet payload')
}
callback(null)
}