agco-amqp-client

0.0.5 • Public • Published

Build Status Coverage Status

AMQP Client

A node module for amqp consumers and producers

Config

Provide a config in the following format. The queues object must contain at least 1 queue for a producer, and at least 2 queues for a consumer. This is because, for each queue that a consumer is bound to, must also have a failure queue for retries.

const config = {
  rabbitMqUrl: 'amqp://guest:guest@localhost:5672',
  topicExchanges: {
    'data.test': {
      options: {
        durable: true
      }
    }
  },
  queues: {
    defaultWorkQueue: {
      options: {
        durable: true
      },
      bindToTopic: {
        exchange: 'data.test',
        key: '*'
      }
    },
    defaultFailQueue: {
      options: {
        durable: true
      }
    }
  }
};

Use

Publishers:

const client = new AmqpClient(config);

client.init()
.then(() => {
    return client.publish('data.test', 'someKey', messageText);
})

Consumers:

const client = new AmqpClient(config);

const Promise = require('bluebird');

const messageHandler = (msg) => {
  console.log(msg.content.toString());
  // must return a promise to resolve or reject message!
  return Promise.resolve();
};

client.init()
.then(() => {
    return client.consume('defaultWorkQueue', 'defaultFailQueue', messageHandler);
})

Testing

npm test

Readme

Keywords

Package Sidebar

Install

npm i agco-amqp-client

Weekly Downloads

1

Version

0.0.5

License

ISC

Unpacked Size

8.66 kB

Total Files

12

Last publish

Collaborators

  • agcodev
  • andreymoser
  • vinnylinck
  • mavdi
  • hvhallmann