Rabbit Message Queue

Installing on Homebrew

Step 1

1
$ brew update

Step 2

1
$ brew install rabbitmq

Step 3

1
$ rabbitmqctl status

Example

Client

send.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function (err, conn) {
conn.createChannel((err, ch) => {
const q = 'hello';
const msg = 'Hello World!';

ch.assertQueue(q, { durable: false });
ch.sendToQueue(q, new Buffer('Hello world'));
console.log(" [x] Sent 'Hello World!'");

});
setTimeout(function () { conn.close(); process.exit(0) }, 500);
});

Server

receive.js

1
2
3
4
5
6
7
8
9
10
11
12
13
const amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function (err, conn) {
conn.createChannel((err, ch) => {
const q = 'hello';
const msg = 'Hello World!';

ch.assertQueue(q, { durable: false });
ch.sendToQueue(q, new Buffer('Hello world'));

});
setTimeout(function () { conn.close(); process.exit(0) }, 500);
});

Result

Demo Result

參考文章

install