Introduction to Apache Kafka® for Python Programmers | Confluent
In this blog post, we're going to get back to basics and walk through how to get started using Apache Kafka with your Python applications.
www.confluent.io
https://data-newbie.tistory.com/252
[Python] confluent-Kafka 연습하기
## Producer 1 (topic odd) from confluent_kafka import Producer import numpy as np p = Producer({'bootstrap.servers': 'localhost'}) def delivery_report(err, msg): """ Called once for each message pro..
data-newbie.tistory.com
from confluent_kafka import Consumer, KafkaError
settings = {
'bootstrap.servers': 'kafka:9092',
'group.id': 'mygroup',
'client.id': 'myclient',
'enable.auto.commit': False,
'session.timeout.ms': 6000,
'default.topic.config': {'auto.offset.reset': 'earliest'}
}
c = Consumer(settings)
c.subscribe(['topic'])
try:
while True:
msg = c.poll(1)
if msg is None:
continue
elif not msg.error():
print('Received message: {0}:::{1}'.format(
msg.offset(), msg.value()))
elif msg.error().code() == KafkaError._PARTITION_EOF:
print('End of partition reached {0}/{1}'
.format(msg.topic(), msg.partition()))
else:
print('Error occured: {0}'.format(msg.error().str()))
except KeyboardInterrupt:
pass
finally:
c.close()
'Python' 카테고리의 다른 글
Python Proxy (0) | 2021.11.03 |
---|---|
Instaloader (0) | 2021.09.21 |
Ubuntu 20.04 / 18.04 / Debian 10에 Homebrew 설치 (0) | 2021.09.11 |
Slack Bot (0) | 2021.08.15 |
pyenv (0) | 2021.08.04 |