8000 refactored receive.js · syk-coder/rabbitmq-tutorials@2030f47 · 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 2030f47

Browse files
committed
refactored receive.js
1 parent 1143a0c commit 2030f47

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

javascript-nodejs/src/receive.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
#!/usr/bin/env node
22

3-
var amqp = require('amqplib');
3+
var amqp = require('amqplib/callback_api');
44

5-
var conn = amqp.connect('amqp://localhost');
6-
conn.then(createChannel).then(null, console.warn);
5+
amqp.connect('amqp://localhost', function(err, conn) {
6+
conn.createChannel(function(err, ch) {
7+
var q = 'hello';
78

8-
function createChannel(conn) {
9-
process.once('SIGINT', function() { conn.close(); });
10-
return conn.createChannel().then(consume);
11-
}
12-
13-
function consume(ch) {
14-
var ok = ch.assertQueue('hello', {durable: false});
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-
});
21-
22-
return ok.then(function(_consumeOk) {
23-
console.log(' [*] Waiting for messages. To exit press CTRL+C');
9+
ch.assertQueue(q, {durable: false});
10+
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
11+
ch.consume(q, function(msg) {
12+
console.log(" [x] Received %s", msg.content.toString());
13+
}, {noAck: true});
2414
});
25-
}
15+
});

0 commit comments

Comments
 (0)
0