@autolotto/bunnyhop-handler

0.1.2 • Public • Published

bunnyhop-handler

Provides convention based message/event handler definition for distributed services using bunnyhop.

Configuration

const Bunnyhop = require('@autolotto/bunnyhop')
const bunnyhop = Bunnyhop('my_service');
const bunnyhopHandler = require('@autolotto/bunnyhop-handler');

bunnyhopHandler({
  bunnyhop,
  path: './path/to/handlers/**/*.handler.js',
  //path: [`/path/to/*good.js', './path/to/**/*.js'] 
  onHandlerCompleted: (msg, returnValue) => { /* optional callback when handler completes */ },
  errorHandler: (err) => { /* optional error handler if an error is thrown or handler returns rejected promise */ }
})

You can turn on debugging to see how many handlers matched by providing the DEBUG=bunnyhop-handler which uses the debug module.

Handler Definition

Listener handler

Note that listen does not support * or # in the routing key

module.exports = {
  autoAck: false, // Optional (default true), provides msg.ack and msg.reject for manual acknowledgements
  where: msg => msg.content.arbitrary === true, // Optional filter for messages received
  routingKey: 'A.B.C', // Message routing key to match
  listen: function (msg) {
    console.log('Doing something with msg data', msg.content);
  }
}
Subscribe handler
// listener type handler
module.exports = {
  autoAck: false, // Optional (default true), provides msg.ack and msg.reject for manual acknowledgements
  where: msg => msg.content.arbitrary === true, // Optional filter for messages received
  routingKey: 'A.*.#', 
  subscribe: function (msg) {
    console.log('Doing something with msg data', msg.content);
  }
}

Package Sidebar

Install

npm i @autolotto/bunnyhop-handler

Weekly Downloads

1

Version

0.1.2

License

MIT

Last publish

Collaborators

  • rpeterson