@novice1/amqp-client
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@novice1/amqp-client

AMQP 0-9-1 client. Sends messages with predefined headers. Extends amqplib.

Installation

$ npm install @novice1/amqp-client

Usage

publisher.js

const AMQPClient = require('@novice1/amqp-client');

const publisher = new AMQPClient(
  // url
  'amqp://guest:guest@localhost:5672/',
  // socket options
  null,
  // predefined headers for all messages sent
  {
    clientCode: 'guest101'
  }
);

publisher.connect().then((conn) => {
    return conn.createChannel();
  })
  .then((ch) => {
    return ch
      .assertQueue('queue_name', { durable: false })
      .then(function () {
        return ch.sendToQueue(
            'queue_name',
            Buffer.from('message')
          );
      });
  })
  .catch(console.error);

consumer.js

const AMQPClient = require('@novice1/amqp-client');

const consumer = new AMQPClient(
  // url
  'amqp://guest:guest@localhost:5672/'
);

consumer.connect().then((conn) => {
    return conn.createChannel();
  })
  .then((ch) => {
    return ch
      .assertQueue('queue_name', { durable: false })
      .then(function () {
        return ch.consume('queue_name', (msg) => {
          let senderIP = msg.properties.headers.senderIP;
          let clientCodeHeader = msg.properties.headers.clientCode;
          let body = msg.content.toString();
          console.log(" [x] Received '%s' from '%s' with clientCode '%s'", body, senderIP, clientCodeHeader);
        });
      });
  })
  .catch(console.error);

References

Readme

Keywords

Package Sidebar

Install

npm i @novice1/amqp-client

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

11.3 kB

Total Files

13

Last publish

Collaborators

  • demingongo