@eliware/rabbitmq
v1.1.1
Published
A simple, testable RabbitMQ client for Node.js supporting both ESM and CommonJS.
Maintainers
Readme
@eliware/rabbitmq 


A simple, testable RabbitMQ client for Node.js supporting both ESM and CommonJS.
Table of Contents
Features
- Publish and consume messages with RabbitMQ using a simple API
- Supports both ESM and CommonJS
- Testable: allows injection of amqplib and logger for mocking
- TypeScript type definitions included
- Minimal dependencies
Installation
npm install @eliware/rabbitmqUsage
ESM Example
import rabbitmq from '@eliware/rabbitmq';
// Publish a message
await rabbitmq.publish('myqueue', 'direct', { hello: 'world' });
// Consume messages
await rabbitmq.consume('myqueue', 'direct', (msg) => {
console.log('Received:', msg);
});CommonJS Example
const rabbitmq = require('@eliware/rabbitmq');
// Publish a message
rabbitmq.publish('myqueue', 'direct', { hello: 'world' });
// Consume messages
rabbitmq.consume('myqueue', 'direct', (msg) => {
console.log('Received:', msg);
});API
publish(queue, type, message, options?, { amqplibLib, logger }?)
Publishes a message to a RabbitMQ exchange.
queue(string): The exchange/queue nametype(string): The exchange type (e.g., 'direct', 'fanout', 'topic')message(any): The message payload (will be JSON-stringified)options(object, optional): Exchange options{ amqplibLib, logger }(object, optional): For dependency injection/testing
consume(queue, type, onMessage, options?, { amqplibLib, logger }?)
Consumes messages from a RabbitMQ queue.
queue(string): The queue nametype(string): The exchange typeonMessage(function): Callback for each message (receives parsed message)options(object, optional): Queue/exchange options{ amqplibLib, logger }(object, optional): For dependency injection/testing
_resetRabbitMQTestState()
Closes any open connections/channels (for test cleanup).
TypeScript
Type definitions are included:
import rabbitmq, { publish, consume, _resetRabbitMQTestState } from '@eliware/rabbitmq';
await publish('myqueue', 'direct', { foo: 'bar' });
await consume('myqueue', 'direct', async (msg) => {
// handle message
});Support
For help, questions, or to chat with the author and community, visit:
License
MIT © 2025 Eli Sterling, eliware.org



