RabbitMQ-Easy
An easy-to-use RabbitMQ library for Node.js, based on AMQP.node (amqplib). RabbitMQ is a high-performance MQ.
Server Environment
- Install Docker (Docker CE recommended)
- Install RabbitMQ:
docker pull rabbitmq:management
- Start RabbitMQ:
docker run --restart=always --name rabbitmq -d -p 5672:5672 -p 15672:15672 rabbitmq:management
- Login to RabbitMQ management web page:
http://localhost:15672/
(guest/guest)
Installation
npm install rabbitmq-easy --save
Usage
1. Basic
receive.js
const MQ = ;const queue = 'q1'; // Name queue as "q1"const mq = ; // Create a message queue // Handle the message comes from queue "q1"const handler = async { console;}; const main = async { // Receive messages comes from queue "q1" in RabbitMQ await mq;}; ;
send.js
const MQ = ;const queue = 'q1'; // Name queue as "q1"const mq = ; // Create a message queue const main = async { // Send a message to queue "q1" in RabbitMQ await mq;}; ;
2. Default Queue
receive.js
const mq = ; const handler = async { console;}; const main = async { await mq;}; ;
send.js
const mq = ; const main = async { await mq;}; ;
3. Multiple Queues
receive.js
const mq = ; const handler1 = async { console;}; const handler2 = async { console;}; const main = async { await mq; await mq;}; ;
send.js
const mq = ; const main = async { await mq; await mq;}; ;
4. Options
const MQ = ; // The options can be omitted if options.rabbitMQ.host is 'localhost'const options = rabbitMQ: host: 'localhost' ; const mq = ;...
Examples
See examples to learn more.
Test
git clone https://github.com/hiowenluke/rabbitmq-easy.gitcd rabbitmq-easynpm installnpm test
Performance
Run benchmark
node ./benchmark/index.js
Results
Running scripts...Benchmarking [10000] times, [10] runs.Starting...Run #1: 0.243 seconds, 41152 times/sec Run #2: 0.089 seconds, 112359 times/sec Run #3: 0.098 seconds, 102040 times/sec Run #4: 0.099 seconds, 101010 times/sec Run #5: 0.086 seconds, 116279 times/sec Run #6: 0.085 seconds, 117647 times/sec Run #7: 0.105 seconds, 95238 times/sec Run #8: 0.118 seconds, 84745 times/sec Run #9: 0.092 seconds, 108695 times/sec Run #10: 0.08 seconds, 125000 times/sec Done.Average: 0.11 seconds, 100417 times/sec----------------------------------------Platform info:macOS Mojave 10.14 x64Intel Core i7-4558U CPU @ 2.80GHz x 4Total Memory 16 GBNode.js v10.16.3V8 6.8.275.32-node.54
License
Copyright (c) 2019, Owen Luke