San*_*sle 2 apache-kafka kafka-consumer-api
我有一个 kakfa 使用者,其enable.auto.commit设置为false。每当我重新启动我的消费者应用程序时,它总是再次读取最后提交的偏移量,然后是下一个偏移量。
例如。最后提交的偏移量是 50。当我重新启动消费者时,它再次首先读取偏移量 50,然后读取下一个偏移量。
我正在执行 commitsync,如下所示。
Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
offsets.put(new TopicPartition("sometopic", partition), new OffsetAndMetadata(offset));
kafkaconsumer.commitSync(offsets);
Run Code Online (Sandbox Code Playgroud)
我尝试将auto.offset.reset设置为最早和最晚,但它并没有改变行为。
我在消费者配置中遗漏了什么吗?
config.put(ConsumerConfig.CLIENT_ID_CONFIG, "CLIENT_ID");
config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
config.put(ConsumerConfig.GROUP_ID_CONFIG, "GROUP_ID");
config.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,StringDeserializer.class.getName());
config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,CustomDeserializer.class.getName());
config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2051 次 |
| 最近记录: |