feat: replication example
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user