An event emitter that uses MongoDB capped collections.
npm install @sealsystems/mongo-notification
An event emitter and receiver that uses MongoDB capped collections.
``shell`
$ npm install @sealsystems/mongo-notification
First you need to add a reference to @sealsystems/mongo-notification to your application.
`javascript`
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:
`javascript`
const notification = await mongoNotification({
url: 'mongodb://...',
topic: 'messages',
collectionSize: '1MB',
writeOnly: false
});
The options contain:
- url mandatory, a connection string,topic
- mandatory, the name of a topic collectioncollectionSize
- optional, the size of the capped collection, default: 1MBwriteOnly
- optional, the open mode, default: false
- Additional @sealsystems/mongo options
Call the emit function for actually emitting an event:
`javascript`
notification.emit('foo', { foo: 'bar' });
Optionally you may specify a callback to get notified when the event has been persisted:
`javascript`
notification.emit('foo', { foo: 'bar' }, (err) => {
// ...
});
If you want to receive events send by your application use the on function:
`javascript`
notification.on('foo', (payload) => {
// ...
});
If you only want to emit events but not receive any you can set the writeOnly option to true when connecting.
`javascript`
const notification = await mongoNotification({
...
writeOnly: true
});
To build this module use roboter.
`shell``
$ bot