27 lines
650 B
JavaScript
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);
|
|
});
|
|
});
|