beatrix-events

3.4.1 • Public • Published

beatrix-events

System for emitting and reacting to events using Beatrix / RabbitMQ

Events are optionally filtered using Sift

Sample usage

const Manager = require('beatrix-events');
 
Manager.connect({
  name: 'blah', // name of this application, for namespacing queues
  uri: 'amqp://guest:guest@localhost/' // would normally be passed based on environment settings
});
 
// listen for all types of people
Manager.on('colony.people', {
  persistent: true, // enqueue events of this type even when this consumer isnt alive
  filter: {age: {$gt: 30}} // only run the method for people over 20
}, async (person) => {
  if (person.name > 'Logan') {
    throw new Error('Run, Logan, Run')
  }
  return person.name + ' was eliminated for the greater good';
})
 
setInterval(() => {
  Manager.emit('colony.people', generateRandomPerson());
}, 1000);

Dependents (0)

Package Sidebar

Install

npm i beatrix-events

Weekly Downloads

2

Version

3.4.1

License

ISC

Unpacked Size

4.43 kB

Total Files

4

Last publish

Collaborators

  • richthegeek