我是卡夫卡的新手。通过一些 kafka-python 在线教程的帮助,我编写了以下代码:
from kafka import SimpleProducer, KafkaClient, KafkaConsumer
kafka = KafkaClient("localhost:9092")
producer = SimpleProducer(kafka)
producer.send_messages(b'my-topic', b'this method', b'Hello World')
consumer = KafkaConsumer('my-topic',
group_id='my_group',
bootstrap_servers=['localhost:9092'])
for message in consumer:
print("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,
message.offset, message.key,
message.value))
但问题是,在最后一个 for 循环中,代码执行被卡住了,我无法弄清楚。