python&kafka集群取消息
2021-05-06 10:30
标签:click new boot span false numbers tool cli port 安装 pip3 install setuptools pip3 install pykafka pip3 install kafka-python 单台kafka kafka集群 可成功拿到消息 python&kafka集群取消息 标签:click new boot span false numbers tool cli port 原文地址:https://www.cnblogs.com/jxba/p/13189886.htmlimport sys
from kafka import KafkaConsumer
from kafka.structs import TopicPartition
consumer = KafkaConsumer(
enable_auto_commit=False,
bootstrap_servers=["xxx-xx-x-sh-yyy-Eyy.yd.com:1234"])
consumer.subscribe(topics=(‘indata_str_abcde_click_new‘))
if sys.getdefaultencoding() != ‘utf-8‘:
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
for message in consumer:
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value.decode()))
bootstrap_servers 参数使用‘‘,‘‘,‘‘隔开
import sys
from kafka import KafkaConsumer
from kafka.structs import TopicPartition
consumer = KafkaConsumer(
enable_auto_commit=False,
bootstrap_servers=["xxx-xx-x-sh-yyy-Eyy.yd.com:1234","xxx-xx-x-sh-yyy-Eyy.yd.com:1231","xxx-xx-x-sh-yyy-Eyy.yd.com:1232"])
consumer.subscribe(topics=(‘indata_str_abcde_click_new‘))
if sys.getdefaultencoding() != ‘utf-8‘:
reload(sys)
sys.setdefaultencoding(‘utf-8‘)
for message in consumer:
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value.decode()))
下一篇:【数据结构】排序