@wuyuchentr/message-broker-lite
v1.0.0
Published
Lightweight AMQP 0-9-1 compatible message broker for embedded scenarios. Drop-in RabbitMQ replacement that runs as a node_module.
Maintainers
Readme
@wuyuchentr/message-broker-lite
Lightweight AMQP 0-9-1 compatible message broker for embedded scenarios. A RabbitMQ reimplementation in pure Node.js that runs as a node_module — no separate RabbitMQ installation needed.
Install
npm install -g @wuyuchentr/message-broker-liteQuick start
# Start broker on default port 5672
message-broker-lite
# With disk persistence
message-broker-lite --data ./data
# Custom port
message-broker-lite --port 5672Connect from any AMQP client (e.g. amqplib):
const amqp = require('amqplib');
async function main() {
const conn = await amqp.connect('amqp://localhost:5672');
const ch = await conn.createChannel();
await ch.assertQueue('my-queue');
await ch.bindQueue('my-queue', '', 'my-key');
ch.consume('my-queue', msg => {
console.log('Received:', msg.content.toString());
ch.ack(msg);
});
ch.sendToQueue('my-queue', Buffer.from('hello'));
}Usage as a library
const { createBroker, start } = require('@wuyuchentr/message-broker-lite');
// Embedded in your app
async function main() {
const { broker, server } = await start({ port: 5672 });
console.log('Broker running on port 5672');
}API
createBroker(options)
Create a broker without starting the server.
| Option | Default | Description |
|--------|---------|-------------|
| port | 5672 | TCP port |
| host | 0.0.0.0 | Bind address |
| heartbeat | 60 | Heartbeat interval (seconds) |
| channelMax | 2047 | Maximum channels |
| frameMax | 131072 | Maximum frame size (bytes) |
| persistenceDir | null | Directory for disk persistence (null = in-memory only) |
start(options)
Create and start the broker. Returns { broker, server }.
server.close()
Gracefully stop the broker.
Exchange types
| Type | Routing |
|------|---------|
| direct | Exact routing key match |
| topic | Pattern match with * (word) and # (multi-word) wildcards |
| fanout | Delivers to all bound queues |
| headers | Matches on message header properties with x-match |
Persistence
Messages, queues, exchanges, and bindings are persisted to disk when persistenceDir is set. Data is recovered on restart. Uses JSON line-delimited files (no native dependencies).
Protocol support
- AMQP 0-9-1
- Connection negotiation (PLAIN auth)
- Channel multiplexing (up to channelMax)
- Exchange declare / delete / bind / unbind
- Queue declare / delete / bind / unbind / purge
- Publish / consume / ack / nack / reject
- Basic QoS (prefetch)
- Transaction support (select / commit / rollback)
- Heartbeat
License
MIT
