Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aedes-persistence

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aedes-persistence

The spec for an Aedes persistence, with abstract tests and a fast in-memory implementation.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
39K
increased by23.82%
Maintainers
1
Weekly downloads
 
Created
Source

aedes-persistence  Build Status

The spec for an Aedes persistence, with abstract tests and a fast in-memory implementation.

Install

To install aedes-persistence, simply use npm:

npm install aedes-persistence --save

API


persistence([opts])

Creates a new instance of a persistence, that is already ready to operate. The default implementation is in-memory only.


instance.storeRetained(packet, callback(err))

Store a retained message, calls the callback when it was saved.


instance.createRetainedStream(pattern)

Return a stream that will load all retained messages matching the given pattern (according to the MQTT spec) asynchronously.


instance.addSubscriptions(client, subscriptions, callback(err, client))

Add the given offline subscriptions for the given Client. The client must have connected with clean: false, as this is not checked here. This is called when a client issue a SUBSCRIBE packet.

subscriptions is in the same format of the subscribe property in the SUBSCRIBE packet:

[{
  topic: 'hello/world',
  qos: 1,
}, {
  topic: 'hello/#',
  qos: 2,
}]

instance.removeSubscriptions(client, subscriptions, callback(err, client))

The inverse of addSubscriptions.


instance.subscriptionsByClient(client, callback(err, subscriptions, client))

Returns all the offline subscriptions for the given client. Called when a client with clean: false connects to restore its subscriptions.

subscriptions is in the same format of the subscribe property in the SUBSCRIBE packet:

[{
  topic: 'hello/world',
  qos: 1,
}, {
  topic: 'hello/#',
  qos: 2,
}]

instance.countOffline(cb(err, numOfSubscriptions, numOfClients)

Returns the number of offline subscriptions and the number of offline clients.


instance.subscriptionsByTopic(pattern, callback(err, subscriptions))

Returns all the offline subscriptions matching the given pattern. Called when a PUBLISH with qos: 1 or qos: 2 is received.

The subscriptions are in the format:

{
  clientId: client.id,
  topic: sub.topic,
  qos: sub.qos
}

instance.cleanSubscriptions(client, callback(err, client))

Removes all offline subscriptions for a given client.


instance.outgoingEnqueue(subscription, packet, callback(err))

Enqueue a potentially offline delivery. subscription is one of the objects returned by subscriptionsByTopic.


instance.outgoingUpdate(client, packet, callback(err))

Called before a (potentially) offline packet is delivered, the caller should update the packet.messageId before updating.


instance.outgoingClearMessageId(client, packet, callback(err))

Removes a packet with the given messageId (passing a PUBACK is ok) from the persistence.


instance.outgoingStream(client)

Return a stream that will load all offline messages for the given client asynchronously.


instance.incomingStorePacket(client, packet, cb(err, packet))

Store an incoming packet for the given client. Used for QoS 2.


instance.incomingGetPacket(client, packet, cb(err, packet))

Retrieve an incoming packet with the same messageId for the given client. Used for QoS 2.


instance.incomingDelPacket(client, packet, cb(err, packet))

Deletes incoming packet with the same messageId for the given client. Used for QoS 2.


instance.putWill(client, packet, cb(err))

Stores the will of a client. Used to support multi-broker environments and to not lose wills in case of a crash.


instance.getWill(client, packet, cb(err))

Retrieves the will of a client. Used to support multi-broker environments and to not lose wills in case of a crash.


instance.delWill(client, packet, cb(err))

Removes the will of a client. Used to support multi-broker environments and to not lose wills in case of a crash.


instance.streamWill(brokers)

Streams all the wills for the given brokers. The brokers are in the format:

{
  mybroker: {
    brokerId: 'mybroker'
  }
}

Implement another persistence

A persistence needs to pass all tests defined in ./abstract.js. You can import and use that test suite in the following manner:

var test = require('tape').test
var myperst = require('./')
var abs = require('aedes-persistence/abstract')

abs({
  test: test,
  persistence: myperst
})

License

MIT

Keywords

FAQs

Package last updated on 29 Dec 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc