简体   繁体   English

卡夫卡消费者不显示消息

[英]Kafka consumer not displaying the message

I am trying to understand how a Kafka producer works.我试图了解 Kafka 制作人是如何工作的。 Below is the python producer code I wrote to send a message.下面是我写的发送消息的python生产者代码。 I started the Kafka console consumer first and then I am running the python code我首先启动了 Kafka 控制台使用者,然后我运行了 python 代码

from confluent_kafka import Producer
from Product import Product
from faker import Faker



if __name__ == '__main__':


    config = {
        "bootstrap.servers":"localhost:9092"
    }
    producer = Producer(config)
    fake = Faker()
    product = Product(fake.name())
    print(product.serial())
    producer.produce(topic="first_topic",value=product.serial())

The issue that I facing is that if I call flush method after calling produce the message appears on the console consumer however without flush the message doesn't appear in the console consumer.我面临的问题是,如果我在调用 generate 之后调用 flush 方法,消息会出现在控制台消费者上,但是如果没有刷新,则消息不会出现在控制台消费者中。 As per Kafka documentation flush will make the producer synchronous.根据 Kafka 文档,flush 将使生产者同步。 Is there a way to avoid using the flush and still make sure the message gets consumed.有没有办法避免使用刷新并仍然确保消息被消耗。 Thank you谢谢

您要么需要刷新,要么需要通过更多消息填充生产者的批量大小,或者通过 confluent_kafka 包中的一些 librdkafka 配置设置将批量大小减少到单个消息以下

您可以按照@OneCricteer 的建议填充批量大小,也可以将 linger.ms 设置为 0。这样它就不会在发送前等待填充到批量大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM