-
Notifications
You must be signed in to change notification settings - Fork 3
/
publisher.js
50 lines (42 loc) · 1.18 KB
/
publisher.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { ServiceBroker } = require("moleculer");
const QueueMixin = require("../../index");
let broker = new ServiceBroker({
logger: console,
transporter: "TCP",
});
const queueMixin = QueueMixin({
connection: "amqp://localhost",
asyncActions: true, // Enable auto generate .async version for actions
});
broker.createService({
name: "publisher",
version: 1,
mixins: [
queueMixin,
],
settings: {
amqp: {
connection: "amqp://localhost", // You can also override setting from service setting
},
},
async started() {
await broker.waitForServices({ name: "consumer", version: 1 });
let name = "repeat_name";
setInterval(async () => {
const response = await broker.call("v1.consumer.hello.async", {
// `params` is the real param will be passed to original action
params: {
name,
},
// `options` is the real options will be passed to original action
options: {
timeout: 12000,
},
});
this.logger.info(`[PUBLISHER] PID: ${process.pid} Called job with name=${name} response=${JSON.stringify(response)}`);
}, 200);
}
});
broker.start().then(() => {
broker.repl();
});