Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit consumer offsets using Camel-kafka?

I am using apache camel to integerate with my kafka messaging. Also i am using JAVA DSL to consume messages from kafka endpoint.

Using apache kafka API's its known how to commit consumer offsets with given properties toggling.

if i disbale auto commit in camel-kafka component how can i commit offsets in apcahe camel then?

I am using below endpoint to disable auto commit in Apache Camel

kafka.consumer.uri = kafka://{{kafka.host}}?zookeeperHost={{zookeeper.host}}&zookeeperPort={{zookeeper.port}}&groupId={{kafka.consumerGroupId}}&topic={{kafka.topic.transformer_t}}&{{kafka.uri.options}}
kafka.uri.options = autoCommitEnable=false
like image 393
usman Avatar asked Nov 09 '22 04:11

usman


1 Answers

Support for manual offset commit was added in CAMEL-11933 and is supported since version 2.21.0. You can enable it with option allowManualCommit=true. This option will expose header CamelKafkaManualCommit, holding instance of KafkaManualCommit, which you can then use e.g. in Processor.

from("kafka:topic?groupId=group&autoCommitEnable=false&allowManualCommit=true")
  //...
  .process(exchange -> {
     exchange.getIn().getHeader(KafkaConstants.MANUAL_COMMIT, KafkaManualCommit.class).commitSync();
  });
like image 102
Bedla Avatar answered Nov 14 '22 22:11

Bedla