README
@sealsystems/mongo-notification
An event emitter and receiver that uses MongoDB capped collections.
Installation
$ npm install @sealsystems/mongo-notification
Quick start
First you need to add a reference to @sealsystems/mongo-notification to your application.
const mongoNotification = require('@sealsystems/mongo-notification');
Then connect to a MongoDB by calling the function mongoNotification. Provide an options object and returns a notification event emitter:
const notification = await mongoNotification({
url: 'mongodb://...',
topic: 'messages',
collectionSize: '1MB',
writeOnly: false
});
The options contain:
urlmandatory, a connection string,topicmandatory, the name of a topic collectioncollectionSizeoptional, the size of the capped collection, default: 1MBwriteOnlyoptional, the open mode, default: false- Additional @sealsystems/mongo options
Emit events
Call the emit function for actually emitting an event:
notification.emit('foo', { foo: 'bar' });
Optionally you may specify a callback to get notified when the event has been persisted:
notification.emit('foo', { foo: 'bar' }, (err) => {
// ...
});
Receive events
If you want to receive events send by your application use the on function:
notification.on('foo', (payload) => {
// ...
});
Write only mode
If you only want to emit events but not receive any you can set the writeOnly option to true when connecting.
const notification = await mongoNotification({
...
writeOnly: true
});
Running the build
To build this module use roboter.
$ bot