【发布时间】:2019-01-09 10:06:37
【问题描述】:
我有一个带有单个分区的 Kafka 主题 (1.0.0)。消费者被打包在一个 EAR 中,当部署到 Wildfly 10 时,最后一条消息的轮询总是返回 0 条消息。虽然题目不是空的。
final TopicPartition tp = new TopicPartition(topic, 0);
final Long beginningOffset = consumer.beginningOffsets(Collections.singleton(tp)).get(tp);
final Long endOffset = consumer.endOffsets(Collections.singleton(tp)).get(tp);
consumer.assign(Collections.singleton(tp));
consumer.seek(tp, endOffset - 1);
当我进行投票时,我得到 0 条记录。尽管记录表明:
Consumer is now at position 377408 while Topic begin is 0 and end is 377409
当我更改为 -2 时:
consumer.seek(tp, endOffset - 2);
我确实收到一条消息:
Consumer is now at position 377407 while Topic begin is 0 and end is 377409
但这当然不是正确的记录,消息 377408 在哪里?
尝试了很多方法来寻求结束等,但它从来没有奏效。
这是我的消费者配置:
Properties properties = new Properties();
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, Configuration.KAFKA_SERVERS.getAsString());
properties.put(ConsumerConfig.GROUP_ID_CONFIG, GROUP_ID);
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, LongDeserializer.class);
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
properties.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, "read_committed");
注意:我尝试了 read_uncommitted 和 read_committed,都给出了相同的结果。
【问题讨论】:
标签: apache-kafka kafka-consumer-api