DAS_2024_1/bondarenko_max_lab_4/publisher.js

25 lines
697 B
JavaScript
Raw Normal View History

2024-12-10 21:33:59 +04:00
const amqp = require('amqplib/callback_api');
2024-12-13 05:48:37 +04:00
amqp.connect('amqp://127.0.0.1', (err, connection) => {
2024-12-10 21:33:59 +04:00
if (err) {
throw err;
}
connection.createChannel((err, channel) => {
if (err) {
throw err;
}
2024-12-13 05:48:37 +04:00
const exchange = 'logs';
const msgTypes = ['Order Received', 'User Message', 'Generate Report'];
2024-12-10 21:33:59 +04:00
2024-12-13 05:48:37 +04:00
channel.assertExchange(exchange, 'fanout', {
durable: false
2024-12-10 21:33:59 +04:00
});
setInterval(() => {
2024-12-13 05:48:37 +04:00
const msg = msgTypes[Math.floor(Math.random() * msgTypes.length)];
channel.publish(exchange, '', Buffer.from(msg));
console.log(" [x] Sent '%s'", msg);
}, 1000);
2024-12-10 21:33:59 +04:00
});
});