Skip to content

Commit 3cc8d23

Browse files
committed
Change Location of how to run link and fix text of how to install RabbitMQ
1 parent 1a16317 commit 3cc8d23

10 files changed

+187
-187
lines changed

how-to-run.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* NodeJS.
66

77
#### How to install RabbitMQ using docker
8-
Install docker run this command:
8+
Install docker and run this command:
99
```bash
1010
docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management
1111
```
@@ -14,56 +14,56 @@ After that, you will be able to access to the management on `0.0.0.0:15672` or `
1414

1515
### Tutorial 1
1616

17-
1. Open a terminal to run the consumer:
17+
* Open a terminal to run the consumer:
1818
```bash
1919
# this will show: [*] Waiting for messages. To exit press CTRL+C
2020
$ node t1-basic-consumer.js
2121
```
2222

23-
2. Open other terminal to run the producer:
23+
* Open other terminal to run the producer:
2424
```bash
2525
# this will show: [x] Sent 'hello world'
2626
$ node t1-basic.js 'hello world.'
2727
```
2828

29-
3. Wait 3 seconds and then you will see `[x] Received 'hello world'` on the consumers terminal.
29+
* Wait 3 seconds and then you will see `[x] Received 'hello world'` on the consumers terminal.
3030

3131
### Tutorial 2
32-
1. Open the terminal to run the consumer:
32+
* Open the terminal to run the consumer:
3333
```bash
3434
# this will show: [*] Waiting for logs. To exit press CTRL+C.
3535
$ node t2-direct-consumer.js SEVERITY
3636
```
3737

38-
2. Open other terminal to run the producer:
38+
* Open other terminal to run the producer:
3939
```bash
4040
# this will show: [x] Sent SEVERITY:'hellow world'
4141
$ node t2-direct.js SEVERITY 'hello world'
4242
```
4343

4444
### Tutorial 3
45-
1. Open the terminal to run the consumer:
45+
* Open the terminal to run the consumer:
4646
```bash
4747
# This command will consume all the messages with a key that match with `logs.#`: `logs.info`, `logs.error`, `logs.warning`
4848
$ node t3-topics-consumer.js 'logs.#'
4949
```
5050

51-
2. Open other terminal to run the producer:
51+
* Open other terminal to run the producer:
5252
```bash
5353
$ node t3-topics.js 'logs.info' 'information message'
5454
$ node t3-topics.js 'logs.error' 'error message'
5555
$ node t3-topics.js 'logs.warning' 'warning message'
5656
```
5757
### Tutotial 4
58-
1. Open the terminal to run the consumer:
58+
* Open the terminal to run the consumer:
5959
```bash
6060
# this consumer will process events only that match with `logs.info`. Also
6161
# this consumer will only accept the messages equal to `hello` and reject the others.
6262
# All the messages rejected will be stored on `queue.dl`.
6363
$ node t4-deadletter-consumer.js 'logs.info'
6464
```
6565

66-
2. Open other terminal to runt the producer:
66+
* Open other terminal to runt the producer:
6767
```bash
6868
# this message is accepted
6969
$ node t4-deadletter.js 'logs.info' 'hello'

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Advanced Message Queuing Protocol
44

55
***
66

7+
### How Run the Examples
8+
See the document [how-to-run.md](how-to-run.md)
9+
710
### Producer
811
Manage the messages to be published so they can be processed.
912

@@ -32,9 +35,6 @@ Rules used for the exchange to send messages to its linked queues.
3235

3336
***
3437

35-
### How Run the Examples
36-
See the document [how-to-run.md](how-to-run.md)
37-
3838
### Reference:
3939
1. https://www.rabbitmq.com/tutorials/amqp-concepts.html
4040
2. http://www.squaremobius.net/amqp.node/channel_api.html

t1-basic-consumer.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
var amqp = require('amqplib');
22

33
amqp.connect('amqp://localhost').then(function (conn) {
4-
return conn.createChannel().then(function (ch) {
5-
// queue to consume
6-
var q = 'queuet1';
4+
return conn.createChannel().then(function (ch) {
5+
// queue to consume
6+
var q = 'queuet1';
77

8-
// we need to make sure that the queue exists
9-
var ok = ch.assertQueue(q, { durable: false});
8+
// we need to make sure that the queue exists
9+
var ok = ch.assertQueue(q, { durable: false});
1010

11-
ok = ok.then(function () {
12-
// initialize the consume event
13-
return ch.consume(q, function (msg) {
14-
setTimeout(function () {
15-
console.log(" [x] Received '%s'", msg.content.toString());
16-
}, 3000);
17-
}, { noAck: true });
18-
});
11+
ok = ok.then(function () {
12+
// initialize the consume event
13+
return ch.consume(q, function (msg) {
14+
setTimeout(function () {
15+
console.log(" [x] Received '%s'", msg.content.toString());
16+
}, 3000);
17+
}, { noAck: true });
18+
});
1919

20-
return ok.then(function (_consumeOk) {
21-
console.log(' [*] Waiting for messages. To exit press CTRL+C');
22-
});
23-
});
20+
return ok.then(function (_consumeOk) {
21+
console.log(' [*] Waiting for messages. To exit press CTRL+C');
22+
});
23+
});
2424
}).then(null, console.warn);

t1-basic.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ var args = process.argv.slice(2);
1313
var msg = args[0] || 'hello world';
1414

1515
amqp.connect('amqp://localhost').then(function(conn) {
16-
// here we use `when` to ensure that the connection is closed
17-
// after the `sendToQueue` event
18-
return when(conn.createChannel().then(function(ch) {
19-
// this will be the name of our new queue.
20-
var q = 'queuet1';
21-
22-
// we need to be sure that the queue `queuet1` exists
23-
// if not, the `assertQueue` method create it.
24-
var ok = ch.assertQueue(q, {durable: false});
25-
26-
return ok.then(function(_qok) {
27-
// after create | validate the existence of the queue
28-
// we are ready to publish messages to it.
29-
ch.sendToQueue(q, new Buffer(msg));
30-
console.log(" [x] Sent '%s'", msg);
31-
32-
// we shouldn't need the channel anymore.
33-
return ch.close();
34-
});
35-
})).ensure(function () { conn.close(); });
16+
// here we use `when` to ensure that the connection is closed
17+
// after the `sendToQueue` event
18+
return when(conn.createChannel().then(function(ch) {
19+
// this will be the name of our new queue.
20+
var q = 'queuet1';
21+
22+
// we need to be sure that the queue `queuet1` exists
23+
// if not, the `assertQueue` method create it.
24+
var ok = ch.assertQueue(q, {durable: false});
25+
26+
return ok.then(function(_qok) {
27+
// after create | validate the existence of the queue
28+
// we are ready to publish messages to it.
29+
ch.sendToQueue(q, new Buffer(msg));
30+
console.log(" [x] Sent '%s'", msg);
31+
32+
// we shouldn't need the channel anymore.
33+
return ch.close();
34+
});
35+
})).ensure(function () { conn.close(); });
3636
}).then(null, console.warn);
3737

t2-direct-consumer.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ var args = process.argv.slice(2);
55
var severity = args[0] || 'info';
66

77
amqp.connect('amqp://localhost').then(function(conn) {
8-
process.once('SIGINT', function() { conn.close(); });
8+
process.once('SIGINT', function() { conn.close(); });
99

10-
return conn.createChannel().then(function(ch) {
11-
var ex = 'direct_logs';
10+
return conn.createChannel().then(function(ch) {
11+
var ex = 'direct_logs';
1212

13-
var ok = ch.assertExchange(ex, 'direct', {durable: false});
13+
var ok = ch.assertExchange(ex, 'direct', {durable: false});
1414

15-
ok = ok.then(function() {
16-
return ch.assertQueue('', {exclusive: true});
17-
});
15+
ok = ok.then(function() {
16+
return ch.assertQueue('', {exclusive: true});
17+
});
1818

19-
ok = ok.then(function(qok) {
20-
var queue = qok.queue;
21-
22-
return ch.bindQueue(queue, ex, severity).then(function() { return queue; });
23-
});
19+
ok = ok.then(function(qok) {
20+
var queue = qok.queue;
21+
22+
return ch.bindQueue(queue, ex, severity).then(function() { return queue; });
23+
});
2424

25-
ok = ok.then(function(queue) {
26-
return ch.consume(queue, logMessage, {noAck: true});
27-
});
25+
ok = ok.then(function(queue) {
26+
return ch.consume(queue, logMessage, {noAck: true});
27+
});
2828

29-
return ok.then(function() {
30-
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
31-
});
29+
return ok.then(function() {
30+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
31+
});
3232

33-
function logMessage(msg) {
34-
console.log(" [x] %s:'%s'",
35-
msg.fields.routingKey,
36-
msg.content.toString());
37-
}
38-
});
33+
function logMessage(msg) {
34+
console.log(" [x] %s:'%s'",
35+
msg.fields.routingKey,
36+
msg.content.toString());
37+
}
38+
});
3939
}).then(null, console.warn);

t2-direct.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ var severity = args[0] || 'info';
99
var message = args[1] || 'Hello World!';
1010

1111
amqp.connect('amqp://localhost').then(function(conn) {
12-
return when(conn.createChannel().then(function(ch) {
13-
// the exchange name used to receive all the messages
14-
var ex = 'direct_logs';
12+
return when(conn.createChannel().then(function(ch) {
13+
// the exchange name used to receive all the messages
14+
var ex = 'direct_logs';
1515

16-
var ok = ch.assertExchange(ex, 'direct', {durable: false});
16+
var ok = ch.assertExchange(ex, 'direct', {durable: false});
1717

18-
return ok.then(function() {
19-
ch.publish(ex, severity, new Buffer(message));
20-
console.log(" [x] Sent %s:'%s'", severity, message);
21-
return ch.close();
22-
});
23-
})).ensure(function() { conn.close(); });
18+
return ok.then(function() {
19+
ch.publish(ex, severity, new Buffer(message));
20+
console.log(" [x] Sent %s:'%s'", severity, message);
21+
return ch.close();
22+
});
23+
})).ensure(function() { conn.close(); });
2424
}).then(null, console.warn);

t3-topics-consumer.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ var amqp = require('amqplib');
44
var key = process.argv[2] || 'log.info';
55

66
amqp.connect('amqp://localhost').then(function (conn) {
7-
process.once('SIGINT', function() { conn.close(); });
7+
process.once('SIGINT', function() { conn.close(); });
88

9-
return conn.createChannel().then(function(ch) {
10-
var ex = 'topic_logs';
11-
var ok = ch.assertExchange(ex, 'topic', {durable: false});
12-
13-
ok = ok.then(function() {
14-
return ch.assertQueue('', {exclusive: true});
15-
});
16-
17-
ok = ok.then(function(qok) {
18-
var queue = qok.queue;
19-
return ch.bindQueue(queue, ex, key).then(function() { return queue; });
20-
});
21-
22-
ok = ok.then(function(queue) {
23-
return ch.consume(queue, logMessage, {noAck: true});
24-
});
9+
return conn.createChannel().then(function(ch) {
10+
var ex = 'topic_logs';
11+
var ok = ch.assertExchange(ex, 'topic', {durable: false});
12+
13+
ok = ok.then(function() {
14+
return ch.assertQueue('', {exclusive: true});
15+
});
16+
17+
ok = ok.then(function(qok) {
18+
var queue = qok.queue;
19+
return ch.bindQueue(queue, ex, key).then(function() { return queue; });
20+
});
21+
22+
ok = ok.then(function(queue) {
23+
return ch.consume(queue, logMessage, {noAck: true});
24+
});
2525

26-
return ok.then(function() {
27-
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
28-
});
29-
30-
function logMessage(msg) {
31-
console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString());
32-
}
33-
});
26+
return ok.then(function() {
27+
console.log(' [*] Waiting for logs. To exit press CTRL+C.');
28+
});
29+
30+
function logMessage(msg) {
31+
console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString());
32+
}
33+
});
3434
}).then(null, console.warn);

t3-topics.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ var key = args[0] || 'log.info';
77
var message = args[1] || 'Hello World!';
88

99
amqp.connect('amqp://localhost').then(function(conn) {
10-
return when(conn.createChannel().then(function(ch) {
11-
var ex = 'topic_logs';
12-
var ok = ch.assertExchange(ex, 'topic', {durable: false});
10+
return when(conn.createChannel().then(function(ch) {
11+
var ex = 'topic_logs';
12+
var ok = ch.assertExchange(ex, 'topic', {durable: false});
1313

14-
ok = ok.then(function() {
15-
return ch.publish(ex, key, new Buffer(message));
16-
});
14+
ok = ok.then(function() {
15+
return ch.publish(ex, key, new Buffer(message));
16+
});
1717

18-
return ok.then(function() {
19-
console.log(" [x] Sent %s:'%s'", key, message);
20-
return ch.close();
21-
});
22-
})).ensure(function() { conn.close(); })
18+
return ok.then(function() {
19+
console.log(" [x] Sent %s:'%s'", key, message);
20+
return ch.close();
21+
});
22+
})).ensure(function() { conn.close(); })
2323
}).then(null, console.log);

0 commit comments

Comments
 (0)