-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublisher.js
More file actions
21 lines (18 loc) · 853 Bytes
/
publisher.js
File metadata and controls
21 lines (18 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const { connect, getQueue } = require('./amqp');
// connects to rabbitmq
connect(publisher);
// Publisher
function publisher(conn) {
const q = getQueue();
conn.createChannel(on_open); // creates a channel and call `on_open` when done
function on_open(err, ch) {
console.log("Publisher connected");
// this function will be called when the channel is created
// `err` will contain the error object, if any errors occurred
// `ch` will contain the channel object
if (err != null) bail(err); // calls `bail` function if an error occurred when creating the channel
ch.assertQueue(q); // asserts the queue exists
ch.sendToQueue(q, new Buffer.from('Hello World!')); // sends a message to the queue
console.log("[x] Sent 'Hello World!'"); // writes a message to the console
}
}