Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
aedes
Advanced tools
Readme
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.published()
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 to 100
.heartbeatInterval
: the interval at which the broker heartbeat is
emitted, it used by other broker in the cluster, the default is
60000
milliseconds.connectTimeout
: the max number of milliseconds to wait for the CONNECT
packet to arrive, defaults to 30000
milliseconds.Events:
client
: when a new Client connects, arguments:
client
clientDisconnect
: when a Client disconnects, arguments:
client
clientError
: when a Client errors, arguments:
client
err
publish
: when a new packet is published, arguments:
packet
client
subscribe
: when a client sends a SUBSCRIBE, arguments:
subscriptions
, as defined in the subscriptions
property of the
SUBSCRIBE
packet.client
unsubscribe
: when a client sends a UNSUBSCRIBE, arguments:
unsubscriptions
, as defined in the subscriptions
property of the
UNSUBSCRIBE
packet.client
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)
}
It will be called when a client publishes a message. Ovverride to supply custom authorization logic.
instance.authorizeSubscribe = function (client, sub, cb) {
if (sub === 'aaaa') {
return cb(new Error('wrong topic'))
}
if (sub === 'bbb') {
// overwrites subscription
sub = '42'
}
callback(null, sub)
}
It will be after a message is published.
client
will be null for internal messages.
Ovverride to supply custom authorization logic.
Disconnects all clients.
Classes for all connected clients.
Events:
error
, in case something bad happendedPublish the given message
to this client. QoS 1 and 2 are fully
respected, while the retained flag is not.
message
is a PUBLISH packet.
callback
will be called when the message has been sent, but not acked.
Subscribe the client to the list of topics.
subscription
can be:
{ topic: topic, qos: qos }
messageId
will send suback to the client.callback
will be called when the subscription is completed.
Disconnects the client
client#publish()
and client#subscribe()
This library is born after a lot of discussion with all Mosca users, and how that was deployed in production. This addresses your concerns about performance and stability.
MIT
FAQs
Stream-based MQTT broker
The npm package aedes receives a total of 16,502 weekly downloads. As such, aedes popularity was classified as popular.
We found that aedes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.