|
| 1 | +const { execSync } = require("child_process"); |
| 2 | +const Rabbit = require("../lib/Rabbit.js"); |
| 3 | +const { rabbitConnection, rabbitUrl, startRabbitCommand, stopRabbitCommand } = require("../test/configuration.js"); |
| 4 | + |
| 5 | +async function sleep(delay) { |
| 6 | + return new Promise((resolve, reject) => { |
| 7 | + setTimeout(resolve, delay); |
| 8 | + }); |
| 9 | +} |
| 10 | + |
| 11 | +async function main() { |
| 12 | + |
| 13 | + // create subscribers |
| 14 | + |
| 15 | + const rabbitSubQueue = new Rabbit({ |
| 16 | + connection: { connectionString: rabbitUrl }, |
| 17 | + serviceName: "beta", |
| 18 | + subQueue: { pesanPizza: (payload) => console.log("Pesan Pizza", payload) }, |
| 19 | + }); |
| 20 | + |
| 21 | + const rabbitSub = new Rabbit({ |
| 22 | + connection: { connectionString: rabbitUrl }, |
| 23 | + serviceName: "beta", |
| 24 | + publisherName: "alpha", |
| 25 | + sub: { pesanBakso: (payload) => console.log("Pesan Bakso", payload) }, |
| 26 | + }); |
| 27 | + |
| 28 | + // restart rabbit |
| 29 | + execSync(stopRabbitCommand); |
| 30 | + execSync(startRabbitCommand); |
| 31 | + |
| 32 | + // create publisher |
| 33 | + |
| 34 | + const rabbitPubQueue = new Rabbit({ |
| 35 | + connection: { connectionString: rabbitUrl }, |
| 36 | + serviceName: "alpha", |
| 37 | + pubQueue: { beta: ["pesanPizza"] }, |
| 38 | + pubPayload: { qty: 2, topping: "cheese" } |
| 39 | + }); |
| 40 | + |
| 41 | + const rabbitPub = new Rabbit({ |
| 42 | + connection: { connectionString: rabbitUrl }, |
| 43 | + serviceName: "alpha", |
| 44 | + pub: { pesanBakso: "pesanBaksoTrigger" }, |
| 45 | + pubPayload: { qty: 3, saos: "tomat" } |
| 46 | + }); |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +main(); |
| 51 | + |
0 commit comments