我有一个标准的 spring kafka 设置,如下所示,
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> feedbackStreamListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}
@KafkaListener(topics = ("my-topic"),groupId = ("groupId"),containerFactory = "listenerContainerFactory")
public void myListener(@Payload String message) {
System.out.println("Received Message : " + message);
// do some heavy processing
}
现在我需要在 3 个场景中自定义日志记录(从我的应用程序生成日志),
答案 0 :(得分:0)
参见 KafkaEvent
实现:https://docs.spring.io/spring-kafka/docs/current/reference/html/#events。
因此,当您在 ConsumerFailedToStartEvent
中捕获 @EventListener
时,您可以使用 ConsumerStartedEvent
记录您想要的任何内容等等。
甚至没有反序列化问题,但是当消费者发生错误时,您绝对可以使用 GenericErrorHandler
来记录某些内容:https://docs.spring.io/spring-kafka/docs/current/reference/html/#annotation-error-handling