简体   繁体   English

Spring Boot Kafka应用程序未收到消息

[英]Spring Boot Kafka application not receiving messages

We're using Spring boot 1.5.4.RELEASE and i can see the following jars in our gradle project: spring-kafka-1.1.6, kafka-clients-0.10.1.1 我们正在使用Spring boot 1.5.4.RELEASE,我可以在gradle项目中看到以下jar:spring-kafka-1.1.6,kafka-clients-0.10.1.1

We have a simple receiver class like below: 我们有一个简单的接收器类,如下所示:

` `

   @KafkaListener(topics = "${mytopic.consume}")
    public void receive(byte[] event) {
        <our code here>...
    }

//$mytopic.consume is being picked up from properties file

` `

The code works fine on most days and i am able to receive events correctly and process them, then suddenly it stops to receive messages. 该代码在大多数情况下都能正常工作,并且我能够正确接收事件并对其进行处理,然后突然停止接收消息。 No error, no warnings. 没有错误,没有警告。 I can see the messages are there on the topic but our listener just doesn't seem to consume them. 我可以看到有关该主题的消息,但是我们的侦听器似乎并没有使用它们。 I tried restarting application, restarting eclipse, change between run and debug mode, change the name of group in kafka properties - but nothing works. 我尝试重新启动应用程序,重新启动eclipse,在运行和调试模式之间切换,更改kafka属性中的组名称-但没有任何效果。 We look at the application after few hours, and there you go - it starts to work again and we receive all the messages which were stuck. 几个小时后,我们查看了该应用程序,然后您就可以开始运行了,并且收到了所有卡住的消息。 Sometimes the problem can last more than a day also. 有时问题可能还会持续超过一天。 My suspicion is its NOT an eclipse issue, but probably the way enterprise Kafka is setup or some bug in Kafka(lesser possibility since i couldn't find such an issue on google). 我的怀疑不是日食问题,而是企业Kafka的安装方式或Kafka中的一些错误(可能性较小,因为我在Google上找不到这样的问题)。 I did notice this issue even when microservice was deployed on IBM bluemix. 即使在IBM Bluemix上部署了微服务时,我也确实注意到了这个问题。

Any pointers will be greatly appreciated. 任何指针将不胜感激。

Here are some of our properties(which might be of interest) that we have configured in our application: ` 这是我们在应用程序中配置的一些属性(可能感兴趣):

acks=all
     retries=0
     batch.size=<a number greater than 10k>
     linger.ms=1
     buffer.memory=<a number in 10s of MBs - our incoming message is just few KBs>
     ENABLE_AUTO_COMMIT_CONFIG=true
     AUTO_COMMIT_INTERVAL_MS_CONFIG=1ms
     SESSION_TIMEOUT_MS_CONFIG=30ms
     zookeeper.sync.time=200ms
     zookeeper.session.timeout=400ms

` `

There is nothing blatantly wrong with the configurations. 配置没有任何公然错误。 I would advise you to step back and start over again. 我建议您退后一步,重新开始。 Create a new Consumer group. 创建一个新的消费者组。 Potentially, also write the code from scratch. 可能还会从头开始编写代码。

Do tests having different number of consumers in a consumer group, note consumers should be equal to or less than number of partitions. 如果测试在一个使用者组中的使用者数量不同,请注意使用者应等于或小于分区数。 Do tests, with different amount of load of messages and see how it works out. 使用不同的消息负载量进行测试,并查看其工作方式。 In the mean while, keep an eye on the Kafka Cluster also, do any brokers leave the cluster, which would change the leaders for the partitions. 同时,还要注意Kafka集群,是否有任何经纪人离开集群,这将改变分区的领导者。 Eventually, you can stop some consumers, and see how rebalance affects your consumers . 最终,您可以阻止一些消费者,并查看重新平衡如何影响您的消费者。

Hope this helps. 希望这可以帮助。

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

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