简体   繁体   English

kafka 没有生产者发送的消息

[英]kafka does not have messages that producer sent

I use spring framework and kafka that has 3 brokers clustered.我使用具有 3 个代理集群的 spring 框架和 kafka。 I found out that consumer did not consume some messages (let say 0.01 percent between all sent messages) so in producer code I log message offset that returned by api:我发现消费者没有消费一些消息(假设所有发送的消息之间有 0.01%),所以在生产者代码中我记录了 api 返回的消息偏移量:

ListenableFuture<SendResult<String, Message>> future = messageTemplate.sendDefault(id, message);
SendResult<String, Message> sendResult = future.get();
String offset = sendResult.getRecordMetadata().offset();

I use return offset to query kafka topic in all partition but it do not find the message (I test other offsets related to messages that consumers used and they are in kafka), whats the problem and how can I insure that message sent to kafka??我使用返回偏移量来查询所有分区中的 kafka 主题,但它没有找到消息(我测试了与消费者使用的消息相关的其他偏移量并且它们在 kafka 中),问题是什么,我如何确保该消息发送到 kafka? ?

I also used messageTemplate.flush();我也用过messageTemplate.flush(); in producer在制作人

I find out that when topic leader of Kafka broker goes down Kafka will rebalance itself and another broker becomes the leader of that partition and if the ack config is not set to all there is a chance of losing some data in this procedure.我发现当 Kafka broker 的 topic leader 出现故障时,Kafka 将重新平衡自身,另一个 broker 成为该分区的 leader,如果ack配置未设置为all ,则有可能在此过程中丢失一些数据。 so change the config to所以将配置更改为

ack=all

also, there is a chance of losing data if minimum in sync replica becomes less than 2, so set it at least to 2.此外,如果同步副本中的最小值小于 2,则有可能丢失数据,因此至少将其设置为 2。

min.insync.replicas = 2

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

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