嗨,我有一个自定义框架,它公开 API 以供发布和使用。我支持很多主题供用户发布和消费。这似乎工作正常,只是偶尔,在我将消息发布到主题后,我的消费者没有收到任何消息。这很奇怪,因为 kafka 已经启动并运行良好。在此错过的消息之前和之后的其他主题的其他消息工作正常。在此事件发生后,同一主题的消息也会发送给消费者。
如果有帮助,我每个主题只有一个分区。当我打开KafaServerLog/data目录并搜索特定主题时,在我的开发环境中,我每次都会看到条目,我发布和消费。但是,发生这种情况的问题(在客户端)日志文件是空的。我在这里错过了什么吗?
Producer api 为您提供了一个回调,您可以使用它来跟踪生产者中偶尔出现的问题。示例代码如下所示:
try (Producer<String, String> producer = new KafkaProducer<>(producerProps)) {
producer.send(new ProducerRecord<String, String>("My-topic", "message payload"), new Callback() {
public void onCompletion(RecordMetadata metadata, Exception ex) {
if (ex != null) {
LOGGER.warn(String.format("Failed to produce record. Got Exception: %s", ex));
} else {
LOGGER.info("Sent record successfully");
}
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句