feat: replication example

This commit is contained in:
2026-01-25 04:56:42 +00:00
parent 15c93c71fb
commit 0beb588a70
5 changed files with 178 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
from kafka import KafkaConsumer
topic_name = "rep-topic"
group_id = "rep-group"
consumer = KafkaConsumer(
topic_name,
bootstrap_servers=['localhost:9092', 'localhost:9094', 'localhost:9096'],
auto_offset_reset='earliest', # start from the beginning if no offset is committed
enable_auto_commit=True, # read = commit, this is True by default
group_id=group_id
)
try:
for message in consumer:
text = message.value.decode('utf-8')
offset = message.offset
print(
f"Received: {text} from partition: {message.partition} at offset: {offset}")
except KeyboardInterrupt:
print("Stopping consumer...")
finally:
consumer.close()