-
Notifications
You must be signed in to change notification settings - Fork 1
/
sender_events.js
35 lines (27 loc) · 964 Bytes
/
sender_events.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
const amqplib = require("amqplib");
const uuid = require("uuid");
const {AMQP_URL} = require("./config");
const dispatchServiceEvent = async (serviceName, eventName, arg) => {
const connection = await amqplib.connect(AMQP_URL);
const channel = await connection.createChannel();
const exchangeName = `${serviceName}.events`;
console.log("Send to exchange ", exchangeName);
await channel.assertExchange(exchangeName, "topic", {
durable: true,
autoDelete: true,
});
const content = new Buffer(arg);
await channel.publish(exchangeName, eventName, content, {
contentType: 'application/json',
contentEncoding: 'utf-8',
deliveryMode: 2, // persistent
});
console.log("Message sent");
setTimeout(() => {
connection.close()
}, 1000);
//await connection.close()
};
(async function() {
await dispatchServiceEvent("service_y", "ping", "hello-from-node.js");
})();