Overview
confluent-kafka 1.9, released on May 10, 2022, improves the AdminClient with new topic and group administration operations.
Main Features
Improved AdminClient
The AdminClient supports new operations like describing consumer groups and managing ACLs programmatically.
python
from confluent_kafka.admin import AdminClient, NewTopic
admin = AdminClient({'bootstrap.servers': 'localhost:9092'})
# Create a topic
topic = NewTopic('my-topic', num_partitions=3, replication_factor=1)
fs = admin.create_topics([topic])
for t, f in fs.items():
f.result() # wait for creation
print(f'Topic {t} created')
Producer and consumer
The Producer and Consumer APIs are optimized for better performance with built-in Avro and JSON Schema serialization.
python
from confluent_kafka import Producer, Consumer
# Producer
producer = Producer({'bootstrap.servers': 'localhost:9092'})
producer.produce('my-topic', key='key', value='message')
producer.flush()
# Consumer
consumer = Consumer({
'bootstrap.servers': 'localhost:9092',
'group.id': 'my-group',
'auto.offset.reset': 'earliest',
})
consumer.subscribe(['my-topic'])
