10000 refactored send.js to make it more simple · rtoth89/rabbitmq-tutorials@fa2dfc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa2dfc6

Browse files
committed
refactored send.js to make it more simple
1 parent 6aacc23 commit fa2dfc6

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

javascript-nodejs/src/send.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
#!/usr/bin/env node
22

3-
var amqp = require('amqplib');
4-
var when = require('when');
3+
var amqp = require('amqplib/callback_api');
54

6-
var conn = amqp.connect('amqp://localhost');
7-
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';
88

9-
function createChannel(conn) {
10-
return when(
11-
conn.createChannel().
12-
then(sendMessage)).
13-
ensure(function() {
14-
conn.close();
15-
});
16-
}
17-
18-
function sendMessage(ch) {
19-
var q = 'hello';
20-
var ok = ch.assertQueue(q, {durable: false});
21-
22-
return ok.then(function(_ignore) {
23-
var msg = 'Hello World!';
24-
ch.sendToQueue(q, new Buffer(msg));
25-
console.log(" [x] Sent '%s'", msg);
26-
return ch.close();
9+
ch.assertQueue(q);
10+
ch.sendToQueue(q, new Buffer('Hello World!'));
11+
console.log(" [x] Sent 'Hello World!'");
2712
});
28-
}
13+
setTimeout(function() { conn.close(); process.exit(0) }, 500);
14+
});

0 commit comments

Comments
 (0)
0