@modulus/rabbit-pubsub

0.2.1 • Public • Published

Rabbit-PubSub

version build license

amqplib wrapper for easier rabbitmq scripting of pub/sub model

Install

npm install @modulus/rabbit-pubsub

Usage

RabbitPubSub(url, [options])

The exported function takes the same parameters as amqplib.connect, and returns a object with two exported functions, publish and subscribe.

Publish(exchange, message, done)

Sends data to subscribers and yields.

const PubSub = require('@modulus/rabbit-rpc')(url)

PubSub.publish('tasks', { message: true }, (err, result) => {
  if (err) throw err // unable to publish

  console.log('message delivered')
})

Subscribe(exchange, worker)

Consumes messages on subscribed topics and passes them to worker. When worker calls done acknowledges the message and sends the result to the client.

const PubSub = require('@modulus/rabbit-rpc')(url)

PubSub.subscribe('tasks', (msg, done) => {
  // do work
  done(null, { result: true })
})

Contribute

Contributions welcome! Please read the contributing guidelines first.

Package Sidebar

Install

npm i @modulus/rabbit-pubsub

Weekly Downloads

3

Version

0.2.1

License

MIT

Last publish

Collaborators

  • csell5
  • bsatrom
  • harlanj
  • fiveisprime
  • jackboberg
  • modulus_deploy