标签:imp 代码 bsp hosts client 类型 logs color div
安装包 pykafka
代码如下:
from pykafka import KafkaClient client = KafkaClient(hosts="test43:9092") print(client.topics) topic = client.topics[b‘rokid‘] #topic名称 consumer = topic.get_simple_consumer() for record in consumer: if record is not None: valuestr = record.value.decode() #从bytes转为string类型 valuedict = eval(valuestr) message = valuedict["message"] fields = message.split("\u0001") for field in fields: kv = field.split("\u0002") if len(kv) == 2: print(kv[0],‘----‘,kv[1]) print(‘-‘*100)
以上仅供开发测试使用,真正发布到线上需要多地方加固。。。
mark
标签:imp 代码 bsp hosts client 类型 logs color div
原文地址:http://www.cnblogs.com/zhzhang/p/6790801.html