DAS_2024_1/bondarenko_max_lab_4/publisher.js
2024-12-10 21:33:59 +04:00

27 lines
650 B
JavaScript

const amqp = require('amqplib/callback_api');
const EXCHANGE_NAME = 'logs';
const EVENT_INTERVAL = 1000;
amqp.connect('amqp://localhost', (err, connection) => {
if (err) {
throw err;
}
connection.createChannel((err, channel) => {
if (err) {
throw err;
}
channel.assertExchange(EXCHANGE_NAME, 'fanout', {
durable: false,
});
setInterval(() => {
const msg = `Event at ${new Date().toISOString()}`;
channel.publish(EXCHANGE_NAME, '', Buffer.from(msg));
console.log(` [x] Sent '${msg}'`);
}, EVENT_INTERVAL);
});
});