-
Notifications
You must be signed in to change notification settings - Fork 4
/
send.js
35 lines (30 loc) · 889 Bytes
/
send.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var amqp = require('amqplib');
var when = require('when');
var channel, connection;
var queue = 'task_queue';
var amqpUrl = 'amqp://localhost';
amqp.connect(amqpUrl)
.then(function (conn) {
connection = conn;
return when(conn.createChannel());
})
.then(function (ch) {
channel = ch;
return channel.assertQueue(queue, {durable: true});
})
.then(function () {
var text = process.argv.slice(2).join(' ') || "Hello World!";
var msg = {
source: 'My service 1',
targetNumber: '89135292926',
msgText: text,
span: 2
};
msg = JSON.stringify(msg);
console.log('msg', msg);
channel.sendToQueue(queue, new Buffer(msg), {deliveryMode: true});
console.log(" [x] Sent '%s'", msg);
return channel.close();
})
.ensure(function() { connection.close(); })
.then(null, console.warn);