Python中基于kafka的融合消费者不起作用
对卡夫卡和阿夫罗来说非常陌生。我被一个问题缠住了,似乎无法找出这里出了什么问题。我写了一本卡夫卡的制作人和消费者书,它使用Avro作为序列化格式。生产者代码工作正常。当我运行kafka avro控制台时,在运行该代码之后,它会给我以下信息-Python中基于kafka的融合消费者不起作用,python,apache-kafka,confluent-platform,Python,Apache Kafka,Confluent Platform,对卡夫卡和阿夫罗来说非常陌生。我被一个问题缠住了,似乎无法找出这里出了什么问题。我写了一本卡夫卡的制作人和消费者书,它使用Avro作为序列化格式。生产者代码工作正常。当我运行kafka avro控制台时,在运行该代码之后,它会给我以下信息- bin/kafka-avro-console-consumer --bootstrap-server localhost:9092 --topic test --property schema.registry.url=http://127.0.0.1:80
bin/kafka-avro-console-consumer --bootstrap-server localhost:9092 --topic test --property schema.registry.url=http://127.0.0.1:8081 --from-beginning
{"name":{"string":"Hello World!"}}
{"name":{"string":"Hello World!"}}
{"name":{"string":"Hello World!"}}
然而,当我尝试在最基本的基础上使用python进行同样的操作时,我编写了以下代码-
from confluent_kafka import KafkaError
from confluent_kafka.avro import AvroConsumer
from confluent_kafka.avro.serializer import SerializerError
class AvroConsumerAdapter(object):
def __init__(self, topic='test'):
self.topic = topic
self.consumer = AvroConsumer({'bootstrap.servers': 'localhost:9092',
'schema.registry.url': 'http://127.0.0.1:8081',
'group.id': 'mygroup'})
self.consumer.subscribe([topic])
def start_consuming(self):
running = True
while running:
try:
msg = self.consumer.poll(10)
if msg:
print(msg.value())
if not msg.error():
print("Here - 1")
print(msg.value())
elif msg.error().code() != KafkaError._PARTITION_EOF:
print("here-2")
print(msg.error())
running = False
else:
print('Here-3')
print(msg.error())
except SerializerError as e:
print("Message deserialization failed for %s: %s" % (msg, e))
running = False
except Exception as ex:
print(ex)
running = False
self.consumer.close()
这个客户永远呆在那里,从不打印任何东西。我不确定这里出了什么问题。谁能帮我一下吗 如果要处理主题中当前的所有数据,请查看-您需要设置auto.offset.reset':“minimate”。默认情况下,它是最大的,这意味着它将只显示生成的新行数据。您可以通过让当前的Python代码运行并生成新的主题消息来验证这一点-您应该看到Python代码将它们收集起来。非常感谢。这帮助我理解并克服了这个问题