1.5.25 • Published 3 years ago

@sealsystems/mongo-notification v1.5.25

Weekly downloads
72
License
MIT
Repository
github
Last release
3 years ago

@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:

  • url mandatory, a connection string,
  • topic mandatory, the name of a topic collection
  • collectionSize optional, the size of the capped collection, default: 1MB
  • writeOnly optional, 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
1.5.25

3 years ago

1.5.24

3 years ago

1.5.21

3 years ago

1.5.23

3 years ago

1.5.22

3 years ago

1.5.19

4 years ago

1.5.20

4 years ago

1.5.18

4 years ago

1.5.14

4 years ago

1.5.13

4 years ago

1.5.16

4 years ago

1.5.15

4 years ago

1.5.17

4 years ago

1.5.12

4 years ago

1.5.10

4 years ago

1.5.11

4 years ago

1.5.9

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.5.5

4 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.6

7 years ago