roger-rabbit: A module that makes the process of consuming and publishing messages in messa…

收藏待读

https://github.com/ignicaodigitalbr/roger-rabbit

Roger Rabbit

Roger Rabbit is a module that makes the process of consuming and publishing messages in message brokers easier. It is a wrapper for amqplib .

Install

npm install roger-rabbit --save

Example

// broker.js
const Broker = require('roger-rabbit');

module.exports = Broker({
  host: 'amqp://guest:[email protected]:5672',
  exchange: {
    type: 'topic',
    name: 'exchange',
  },
});
// consumer.js
const broker = require('./broker');

const queue = {
  name: 'queue.name',
};

broker.consume({ queue }).then({ message, ack, reject } => {
  // do something with message
  ack();
});
// publisher.js
const broker = require('./broker');

broker.publish('queue.name', { message: 'hello world' });

Documentation

Broker

OptionDescriptionRequiredDefault
hostmessage broker connection urlyesnull
loggerlogger objectnoconsole
disableLogdisable log (all levels)nofalse
exchangenonull
queuenonull

Exchange options

OptionDescriptionDefault
typedirect, topic, fanoutempty string (deafault)
nameexchange namenull
options options used in assertExchangenull

Queue options

OptionDescriptionDefault
namequeue namenull
options options used in assertQueuenull

broker.consume

broker.consume expects to receive. Example:

const queue = {
  name: 'queue.name',
  options: {},
};

broker.consume({ queue })
  .then(({ ack, reject, message }) => /* handle success */)
  .catch(error => /* handle error */);

broker.publish

broker.publish expects to receive queue name, message and. Example:

const queue = {
  options: {},
};

broker.publish('queue.name', { message: 'message' }, { queue })
  .then(({ queue, message }) => /* handle success */)
  .catch(error => /* handle error */);

相關閱讀

免责声明:本文内容来源于Github,已注明原文出处和链接,文章观点不代表立场,如若侵犯到您的权益,或涉不实谣言,敬请向我们提出检举。