我有一个卡夫卡消费者; 详情如下:
Version="0.10.0.0"
auto.offset.reset.config="earliest"
enable.auto.commit="false"
当我使用consumeroffsetchecker检查消费者的偏移时,我看到消息滞后为1,总消息数为9
问题 当我以3秒的超时轮询消费者时,即使队列中有1条未被消费者消费的消息(消费者偏移检查器证明),也没有消息返回。 我手动控制提交。我的民意调查循环如下:
while (true)
{
ConsumerRecords<String, T> records = _consumer.poll(3000);
for (TopicPartition partition : records.partitions())
{
_logger.info("Found Kafka Messages");
List<ConsumerRecord<String, T>> partitionRecords = records.records(partition);
for (ConsumerRecord<String, T> record : partitionRecords)
{
_logger.info("Message Received - Partition: {} Offset: {} - Topic {}", record.partition(), record.offset(), record.topic());
try
{
processMessage(record.value());
}
catch (Exception exc)
{
_logger.error("Error processing Message - Partition: {} Offset: {} - Topic {}", record.partition(), record.offset(), record.topic(), exc);
}
}
long lastoffset = partitionRecords.get(partitionRecords.size() - 1).offset();
_logger.info("Committing Kafka Offset - {} Offset {} - Topic {}", lastoffset + 1, partition, topics.get(0) );
_consumer.commitSync(Collections.singletonMap(partition, new OffsetAndMetadata(lastoffset + 1)));
}
}
我认为该消息尚未提交,因为它在偏移检查器中显示为“滞后”
为什么民意调查没有收到消息?
仅供参考我是否在收到该消息后将消息放入队列但是滞后的消息丢失了?
由于