Sobes.tech
Middle+

What data bus did you use and what did you use for reading from Kafka?

sobes.tech AI

Answer from AI

Data transmission often uses Apache Kafka as a data bus — a distributed message streaming platform that provides high throughput and reliability.

To read from Kafka in Python, the kafka-python or confluent-kafka-python library is usually used. For example, with confluent-kafka-python, you can create a consumer and read messages from a topic:

from confluent_kafka import Consumer

conf = {
    'bootstrap.servers': 'localhost:9092',
    'group.id': 'my_group',
    'auto.offset.reset': 'earliest'
}
consumer = Consumer(conf)
consumer.subscribe(['my_topic'])

try:
    while True:
        msg = consumer.poll(1.0)
        if msg is None:
            continue
        if msg.error():
            print(f"Error: {msg.error()}")
            continue
        print(f"Received message: {msg.value().decode('utf-8')}")
finally:
    consumer.close()

Thus, Kafka acts as a data bus, and specialized clients are used in Python to read from it.