Junior — Middle
How confident are you in the concepts and capabilities of Apache Kafka?
sobes.tech AI
Answer from AI
Apache Kafka is a distributed data streaming platform designed for processing large volumes of real-time messages.
Main concepts and features:
- Topics: logical channels for publishing and subscribing to messages.
- Producers: send messages to topics.
- Consumers: read messages from topics, can form groups for parallel processing.
- Partitioning: topics are divided into partitions for scalability and parallelism.
- Delivery guarantees: support for "at least once" and "exactly once" delivery with transactions.
- Message storage: messages are stored on disk with retention policies and re-read capabilities.
Kafka is widely used for event-driven systems, stream analytics, and microservices integration.
Example of a simple producer in Node.js using kafka-node:
const kafka = require('kafka-node');
const client = new kafka.KafkaClient({kafkaHost: 'localhost:9092'});
const producer = new kafka.Producer(client);
producer.on('ready', () => {
const message = 'Hello Kafka';
const payloads = [{ topic: 'test-topic', messages: message }];
producer.send(payloads, (err, data) => {
if (err) console.error(err);
else console.log('Message sent:', data);
});
});
producer.on('error', (err) => {
console.error('Producer error:', err);
});
This demonstrates basic Kafka operation in Node.js.