1단계 - pip install
pip install kafka-python
2단계 - kafka consumer python
from kafka import KafkaConsumer
from json import loads
# topic, broker list
consumer = KafkaConsumer(
'test',
bootstrap_servers=['my-kafka.default.svc.cluster.local:9092'],
enable_auto_commit=True,
)
# consumer list를 가져온다
print('[begin] get consumer list')
for message in consumer:
print("Topic: %s, Partition: %d, Offset: %d, Key: %s, Value: %s" \
% ( message.topic,
message.partition,
message.offset,
message.key,
message.value ))
print('[end] get consumer list')
3단계 - SSL 인증서 추가하기
from kafka import KafkaConsumer
from json import loads
# topic, broker list
caRootLocation='CARoot.pem'
consumer = KafkaConsumer(
'test',
bootstrap_servers=['my-kafka.default.svc.cluster.local:9092'],
enable_auto_commit=True,
security_protocol='SSL',
ssl_check_hostname=True,
ssl_cafile=caRootLocation,
)
# consumer list를 가져온다
print('[begin] get consumer list')
for message in consumer:
print("Topic: %s, Partition: %d, Offset: %d, Key: %s, Value: %s" \
% ( message.topic,
message.partition,
message.offset,
message.key,
message.value ))
print('[end] get consumer list')
🧔참고한곳
Connecting to Kafka cluster using SSL with Python
This article specifically talks about how to write producer and consumer for Kafka cluster secured...
dev.to
'python' 카테고리의 다른 글
| file write (0) | 2022.04.21 |
|---|---|
| main() 함수 추가하기 (0) | 2022.03.24 |
| 현재 시간 표시하기 (0) | 2022.03.24 |
| 전역변수 (0) | 2022.03.24 |
| 문자열 구분자로 나누자 by split() (0) | 2022.03.22 |
