Skip to content
Wrapper for http://www.squaremobius.net/amqp.node/ which simplifies its usage for publishing and subscribing
JavaScript
Branch: master
Clone or download
dependabot-preview and LordotU chore(deps): [security] bump mixin-deep from 1.3.1 to 1.3.2
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2. **This update includes a security fix.**
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](jonschlinkert/mixin-deep@1.3.1...1.3.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
Latest commit 2d1148b Jan 18, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__ Initial commit Jan 4, 2019
docs docs: add docs directory Jan 6, 2019
src fix: add missed msg.fields and msg.properties to onQueueMsg callback Jan 6, 2019
.eslintrc.js Initial commit Jan 4, 2019
.gitignore chore: add .npmrc to .gitignore Jan 6, 2019
.travis.yml chore: Add Travis CI Jan 17, 2020
LICENSE Initial commit Jan 4, 2019
README.md chore: Add Travis CI Jan 17, 2020
package-lock.json chore: Bump version Jan 17, 2020
package.json
yarn.lock chore(deps): [security] bump mixin-deep from 1.3.1 to 1.3.2 Jan 18, 2020

README.md

Amqpator

License Build Status Coverage Status

Description

Wrapper for amqplib which simplifies its usage for publishing and subscribing

Installation

yarn add amqpator

Testing

You should have running RabbitMQ instance with management plugin installed.

yarn test:jest # Run Jest with coverage collection
yarn test:coverage # Send coverage to .coveralls.io
yarn test # yarn test:jest && yarn test:coverage

Also, you may set connection params for this instance via environment variables:

export AMQPATOR_HOST = 'localhost'
export AMQPATOR_PORT = 5672
export AMQPATOR_USERNAME = 'guest'
export AMQPATOR_PASSWORD = 'guest'
export AMQPATOR_VHOST = '/'
export AMQPATOR_PORT_HTTP = 15672

Usage

// Simple echo pub/sub

const Amqpator = require('amqpator')


const amqp = new Amqpator(/* {
  host = 'localhost',
  username = 'guest',
  logger = console,
  onConnectionClose = () => {},
  onConnectionError = () => {},
  connectionOptions = {},
  password = 'guest',
  port = 5672,
  query = { heartbeat: 30 },
  reconnect = true,
  reconnectAttempts = 10,
  reconnectInterval = 299,
  vhost = '/',
} */)

const exchange = 'echo_exchange'
const routingKey = 'echo_exchange_routing_key'

amqp.getSub({
  exchange,
  exchangeOptions: {
    autoDelete: true,
  },

  routingKey,

  queue: 'echo_queue',
  queueOptions: {
    autoDelete: true,
    exclusive: true,
  },

  onQueueMsg: ({ echo }, fields, properties) => {
    console.log(echo, fields, properties)
  },
}).then(
  _ => _.subscribe()
)

amqp.getPub({
  exchange,
  exchangeOptions: {
    autoDelete: true,
  },

  routingKey,
}).then(
  _ => _.publish({
    message: { echo: 'Echo' },
    messageOptions: {
      // expiration (string)
      // userId (string)
      // CC (string or array of string)
      // priority (positive integer)
      // persistent (boolean)
      // deliveryMode (boolean or numeric)
      // mandatory (boolean)
      // BCC (string or array of string)
      // immediate (boolean)
      // contentType (string)
      // contentEncoding (string)
      // headers (object)
      // correlationId (string)
      // replyTo (string)
      // messageId (string)
      // timestamp (positive number)
      // type (string)
      // appId (string)
    },
  )
)
You can’t perform that action at this time.