8000 refactored receive.js · syk-coder/rabbitmq-tutorials@b282cde · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b282cde

Browse files
committed
refactored receive.js
1 parent 05d8e02 commit b282cde

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

javascript-nodejs/src/receive.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
var amqp = require('amqplib');
44

5-
amqp.connect('amqp://localhost').then(function(conn) {
5+
var conn = amqp.connect('amqp://localhost');
6+
conn.then(createChannel).then(null, console.warn);
7+
8+
function createChannel(conn) {
69
process.once('SIGINT', function() { conn.close(); });
7-
return conn.createChannel().then(function(ch) {
10+
return conn.createChannel().then(consume);
11+
}
812

9-
var ok = ch.assertQueue('hello', {durable: false});
13+
function consume(ch) {
14+
var ok = ch.assertQueue('hello', {durable: false});
1015

11-
ok = ok.then(function(_qok) {
12-
return ch.consume('hello', function(msg) {
13-
console.log(" [x] Received '%s'", msg.content.toString());
14-
}, {noAck: true});
15-
});
16+
ok = ok.then(function(_ignore) {
17+
return ch.consume('hello', function(msg) {
18+
console.log(" [x] Received '%s'", msg.content.toString());
19+
}, {noAck: true});
20+
});
1621

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

0 commit comments

Comments
 (0)
0