This is a small POC on Python Kafka Consumer using confluent_kafka
library.
- Python 3
- Virtualenv
- Confluent Cloud Credentials
pip install -r requirements.txt
export KAFKA_BOOTSTRAP_SERVERS=
export KAFKA_API_KEY=
export KAFKA_API_SECRET=
This code contains the KafkaConsumer
class which reads a list of topics and consumes a configurable max_messages
.
Provide the topic list and the consumer configuration
consumer1 = KafkaConsumer(topic_list, config)
Provide the max messages and timeout(in seconds) value to the consume
method. It returns the consumed messages
messages = consumer1.consume(max_messages=5, timeout=10)