简体   繁体   English

在骆驼卡夫卡组件中向卡夫卡发送确认

[英]send acknowledge to kafka in camel-kafka component

I am new to camel-kafka component. 我是骆驼-kafka组件的新手。 I have all the setup to send and receive the messages from kafka server using camel-kafka component. 我有使用骆驼-kafka组件从kafka服务器发送和接收消息的所有设置。 I am using similar code as mentioned below : 我正在使用类似的代码,如下所述:

from("kafka:localhost:9092?topic=test&groupId=testing&autoOffsetReset=earliest&consumersCount=1")
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange)
                                    throws Exception {
                                String messageKey = "";
                                if (exchange.getIn() != null) {
                                    Message message = exchange.getIn();
                                    Integer partitionId = (Integer) message
                                            .getHeader(KafkaConstants.PARTITION);
                                    String topicName = (String) message
                                            .getHeader(KafkaConstants.TOPIC);
                                    if (message.getHeader(KafkaConstants.KEY) != null)
                                        messageKey = (String) message
                                                .getHeader(KafkaConstants.KEY);
                                    Object data = message.getBody();


                                    System.out.println("topicName :: "
                                            + topicName + " partitionId :: "
                                            + partitionId + " messageKey :: "
                                            + messageKey + " message :: "
                                            + data + "\n");
   /// I perform many other operations here like persist the object in DB etc. 
                                }
                            }
                        }); 

Here the problem is because I am not sending any acknowledge back to kafka it is getting same message thrice from the server. 这里的问题是因为我没有将任何确认发回给kafka,它从服务器收到了三次相同的消息。 My question is how can I send back the acknowledge to kafka manually ? 我的问题是如何将确认手动发送回kafka? I have not found any proper documentation in camel-kafka component. 我在camel-kafka组件中找不到任何适当的文档。

You don't need to send an acknowledgement back to kafka. 您无需将确认发送回kafka。 You haven't specified the auto commit enable which defaults to true which means auto commit is set to true. 您尚未指定自动提交启用功能,默认情况下为true,这意味着自动提交设置为true。 That takes care of the acknowledgement. 那负责确认。

Can you please specify which version of kafka does the camel-kafka component use? 您能否指定camel-kafka组件使用哪个版本的kafka? Your camel-kafka setup is fine. 您的骆驼kafka设置很好。 You might be getting duplicate messages because of the version of kafka you are using. 由于您使用的kafka版本,您可能会收到重复的消息。

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

相关问题 骆驼卡夫卡中的客户确认 - Client Acknowledge in camel-kafka Camel-Kafka组件无法正常工作:“因为必须配置代理” - Camel-Kafka component not workingfor error :“because of Brokers must be configured” 在 Camel-Kafka 中创建并发 Kafka 消费者 - Create concurrent Kafka consumers in Camel-Kafka 使用apache camel的camel-kafka组件手动提交消费者偏移 - using apache camel's camel-kafka component to commit consumer offsets manually 在camel-kafka中引发异常时不要提交偏移量 - Do not commit offset when exception is thrown in camel-kafka 如何使用Camel-kafka提交消费者抵消? - How to commit consumer offsets using Camel-kafka? 无法使用 Spingboot 应用程序配置带有 Camel-Kafka 的事务 - Unable to configure Transaction with Camel-Kafka using Spingboot application 骆驼卡夫卡java.io.EOFException-NetworkReceive.readFromReadableChannel - Camel-Kafka java.io.EOFException - NetworkReceive.readFromReadableChannel 使用Camel-Kafka的ProducerTemplate sendBody()方法时,无法为端点创建Producer - Failed to create Producer for endpoint when using Camel-Kafka's ProducerTemplate sendBody() method Kafka:如何使用(手动),操作,确认和将结果发送到新主题 - Kafka : How to consume, manipulate, acknowledge (manually) and send result to new topic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM