Sobes.tech
Junior — Middle

What messaging systems with message brokers have you worked with?

sobes.tech AI

Answer from AI

The following message brokers are often used in working with Node.js:

  • RabbitMQ — a popular broker supporting AMQP, well-suited for complex message routing and guaranteed delivery.
  • Apache Kafka — a high-throughput data stream processing system, often used for event-driven systems and logging.
  • Redis Pub/Sub — a simple publish/subscribe mechanism, suitable for lightweight tasks and caching.

Example of using RabbitMQ with the amqplib library:

const amqp = require('amqplib');

async function sendMessage() {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();
  const queue = 'task_queue';
  const msg = 'Hello World';

  await channel.assertQueue(queue, { durable: true });
  channel.sendToQueue(queue, Buffer.from(msg), { persistent: true });

  console.log(" [x] Sent '%s'", msg);
  setTimeout(() => {
    connection.close();
    process.exit(0);
  }, 500);
}

sendMessage();