简体   繁体   中英

send acknowledge to kafka in camel-kafka component

I am new to camel-kafka component. I have all the setup to send and receive the messages from kafka server using camel-kafka component. 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. My question is how can I send back the acknowledge to kafka manually ? I have not found any proper documentation in camel-kafka component.

You don't need to send an acknowledgement back to kafka. You haven't specified the auto commit enable which defaults to true which means auto commit is set to true. That takes care of the acknowledgement.

Can you please specify which version of kafka does the camel-kafka component use? Your camel-kafka setup is fine. You might be getting duplicate messages because of the version of kafka you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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