wrappitmq – it wraps amqplib for us lazy people!
npm install wrappitmq
This is a Node.JS library for Inter-Process Communication with RabbitMQ based on amqplib (AMQP 0-9-1). It intends to take care of all the complicated stuff and offers you a simple API that just works out of the box and does what you expect it to (don't nail me down on this).
It makes heavy use of async/await and requires node v7.
Producer enqueues a task to be worked on. You may block execution until the Broker confirms that it has received the message. That task will be picked up by one Worker and it will be acknowledged if the consuming function resolves. If an error occurs within the consuming function the error event will be emitted on the queue and the task will be re-enqueued for another try.
const WorkQueue = WorkQueue;// Set-up.const queue =// All these options are optional.prefetch: 1 // How many messages to work on asynchronously (Default: 1)queue: 'workqueue' // Name of the queue to use. (Default: workqueue)url: 'amqp://localhost:5672' // Can also be specified on connect();// URL here is optional, can also be set as above.await queue;queue;queue;// Enqueue a task.await queue;// Consume tasks.const cancel = await queue;// Cancel consumer to stop receiving tasks.await ;// Close connection.await queue;
Publisher publishes a message on a certain topic. You may block execution until the Broker confirms that it has received the message. The message will be broadcast to all Subscribers listening on that topic. There is no acknowledgement and persistence handling for these exchanges. Messages will be lost if nobody has subscribed to the topic.
const PubSub = PubSub;// Set-up.const pubsub =// All these options are optional.exchange: 'pubsub' // Name of the queue to use. (Default: pubsub)url: 'amqp://localhost:5672' // Can also be specified on connect();// URL here is optional, can also be set as above.await pubsub;pubsub;pubsub;// Publish a message.await pubsub;// Subscribe to a topic.const unsub = await pubsub;// Cancel subscription to stop receiving messages.await ;// Close connection.await pubsub;
Run the libraries integration tests with:
$ AMQP_URL="amqp://user:pass@localhost:5672" npm test
To determine test coverage run:
$ AMQP_URL="amqp://user:pass@localhost:5672" npm run coverage
Are always welcome!
- Initial development by @patrickd-
- Name suggested by @leschekfm :D