Sobes.tech
Junior — Middle

Have you used Apache Kafka in your projects or work tasks?

sobes.tech AI

Answer from AI

Yes, I have used Apache Kafka in Node.js projects to facilitate message exchange between microservices. Kafka allows efficient processing of large data streams in real-time, ensuring high performance and reliability.

An example of using Kafka in Node.js with the kafkajs library:

const { Kafka } = require('kafkajs');

const kafka = new Kafka({
  clientId: 'my-app',
  brokers: ['kafka-broker1:9092', 'kafka-broker2:9092']
});

const producer = kafka.producer();

async function sendMessage() {
  await producer.connect();
  await producer.send({
    topic: 'test-topic',
    messages: [
      { value: 'Hello, Kafka!' }
    ]
  });
  await producer.disconnect();
}

sendMessage().catch(console.error);

This approach helps build scalable and fault-tolerant systems.