0.10.4 • Published 7 days ago

amqplib v0.10.4

Weekly downloads
595,134
License
MIT
Repository
github
Last release
7 days ago

AMQP 0-9-1 library and client for Node.JS

NPM version NPM downloads Node.js CI amqplib

npm install amqplib

A library for making AMQP 0-9-1 clients for Node.JS, and an AMQP 0-9-1 client for Node.JS v10+.

This library does not implement AMQP 1.0 or AMQP 0-10.

Project status:

  • Expected to work
  • Complete high-level and low-level APIs (i.e., all bits of the protocol)
  • Stable APIs
  • A fair few tests
  • Measured test coverage
  • Ports of the RabbitMQ tutorials as examples
  • Used in production

Still working on:

  • Getting to 100% (or very close to 100%) test coverage

Callback API example

const amqplib = require('amqplib/callback_api');
const queue = 'tasks';

amqplib.connect('amqp://localhost', (err, conn) => {
  if (err) throw err;

  // Listener
  conn.createChannel((err, ch2) => {
    if (err) throw err;

    ch2.assertQueue(queue);

    ch2.consume(queue, (msg) => {
      if (msg !== null) {
        console.log(msg.content.toString());
        ch2.ack(msg);
      } else {
        console.log('Consumer cancelled by server');
      }
    });
  });

  // Sender
  conn.createChannel((err, ch1) => {
    if (err) throw err;

    ch1.assertQueue(queue);

    setInterval(() => {
      ch1.sendToQueue(queue, Buffer.from('something to do'));
    }, 1000);
  });
});

Promise/Async API example

const amqplib = require('amqplib');

(async () => {
  const queue = 'tasks';
  const conn = await amqplib.connect('amqp://localhost');

  const ch1 = await conn.createChannel();
  await ch1.assertQueue(queue);

  // Listener
  ch1.consume(queue, (msg) => {
    if (msg !== null) {
      console.log('Received:', msg.content.toString());
      ch1.ack(msg);
    } else {
      console.log('Consumer cancelled by server');
    }
  });

  // Sender
  const ch2 = await conn.createChannel();

  setInterval(() => {
    ch2.sendToQueue(queue, Buffer.from('something to do'));
  }, 1000);
})();

Running tests

npm test

To run the tests RabbitMQ is required. Either install it with your package manager, or use docker to run a RabbitMQ instance.

docker run -d --name amqp.test -p 5672:5672 rabbitmq

If prefer not to run RabbitMQ locally it is also possible to use a instance of RabbitMQ hosted elsewhere. Use the URL environment variable to configure a different amqp host to connect to. You may also need to do this if docker is not on localhost; e.g., if it's running in docker-machine.

One public host is dev.rabbitmq.com:

URL=amqp://dev.rabbitmq.com npm test

NB You may experience test failures due to timeouts if using the dev.rabbitmq.com instance.

You can run it under different versions of Node.JS using nave:

nave use 10 npm test

or run the tests on all supported versions of Node.JS in one go:

make test-all-nodejs

(which also needs nave installed, of course).

Lastly, setting the environment variable LOG_ERRORS will cause the tests to output error messages encountered, to the console; this is really only useful for checking the kind and formatting of the errors.

LOG_ERRORS=true npm test

Test coverage

make coverage
open file://`pwd`/coverage/lcov-report/index.html
@xanhz/connectors@amicopo/msamessaging@btcvest/commoncustom-extension@hiennc24/core@654wak654/celery-node@654wak654/celery-ts@log-gdx-logger/gdxlogger@tpboard/slibs@recognition-game/shared-backendamqpemitter@candle-face/shared-backendcnnct@eksi-kitap/rmqalerts-controller@natlibfi/melinda-record-link-migration-commonspromise-rabbitmq-rpc@iopanda/txroutersufferfest-apismiledataguard-mqmanagerpartier-queuehistory-servicequeueballre-amqp-connection-managerrabbitmq-amqpspark-messengerrt3egg-data-sync@aax/loggeregg-amqplib-provocovo-ascoltatoriamqp-testing-josueinx-server@meowwolf/node-red-contrib-mw-amqpnode-red-contrib-mw-amqponewallet.library.rabbitsunguracrmv-consumerquertmblazeamqplib-reconnect-wrapperbets-notifications@thealmondtree/rabbitmq@sensorbucket/source-worker-ttn@aycd/autosolve-clientexpress-sequalizeamqlib-connection-managerservicegithub@lasmala/amqplib-connection-manager@d19n/client@d19n/schema-managerlf-node-commonapge-workflow@nestwealth/message-brokerpygmy-rabbit@jloaiza07/event-managernode-red-contrib-rabbitmq-bus-ac@donsky/node-gateway@donsky/node-service@swarthy/wait-for-rabbitapi-enveveapi-eventbus@nhatnm16100/msx-nestjs@community-fibre/clientevaluation-engineegg-starnet-rabbitmqmq-wrapperusagiemilton@cyberproof/nestjs-rabbitmqbentley-admin-servicebentley-products-servicegeofencesyxapimodulevms-recording-server-node@ccmos/nestjs-amqpbenefide0.0.0-jun.0node_contrastotozotoz-amqp@noma/plugin-amqpton-simple-amqp-workeraeonyxtd.coreplugjs-registry@devticon/nestjs-microservices-rabbitmq@egalteam/egalservice-mailingn8n-nodes-base-ziwo@softwrapco/t3afy-commonpie1@inrange/amqp-message-bus-temp@dotedu/devops-cliisa-synct@fof-nestjs/coremsek-rabbitmq-library@ashok0617/node-red-contrib-amqp@fosscord/server-util@peregrine/mq-lib
0.10.4

7 days ago

0.10.1

2 years ago

0.10.2

2 years ago

0.10.3

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.9.1

2 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.6.0

4 years ago

0.5.6

4 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

6 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago