[英]Handling messages on a dead letter topic using Spring Kafka
We currently have a Dead Letter Topic (DLT) configuration in place by using Spring Kafka (in a Spring Boot application).我们目前使用 Spring Kafka(在 Spring 引导应用程序中)实施了死信主题 (DLT) 配置。 We are using the DeadLetterPublishingRecoverer
within the SeekToCurrentErrorHandler
.我们在SeekToCurrentErrorHandler
中使用DeadLetterPublishingRecoverer
。 We assigned the latter one to the ConcurrentKafkaListenerContainerFactory
.我们将后一个分配给ConcurrentKafkaListenerContainerFactory
。
While processing our first messages;在处理我们的第一条消息时; due to a stupid mistake in our service, we ended up with some NullPointerException
exceptions and 20% of the messages ended up on the DLT (which is expected behaviour and is perfect for us).由于我们的服务中出现了一个愚蠢的错误,我们最终得到了一些NullPointerException
异常,并且 20% 的消息最终出现在 DLT 上(这是预期的行为,对我们来说是完美的)。
We fixed the bug, but now we want to process those 20% messages again.我们修复了这个错误,但现在我们想再次处理那 20% 的消息。 Possibilities we see:我们看到的可能性:
@KafkaEventListener
in our application which reads from the DLT在从 DLT 读取的应用程序中添加第二个@KafkaEventListener
Solution 2 is my preferred solution as moving it back to the original topic also implies that other consumer groups get the message again (should normally be OK, as all of our services are idempotent).解决方案 2 是我首选的解决方案,因为将其移回原始主题也意味着其他消费者组再次收到消息(通常应该没问题,因为我们所有的服务都是幂等的)。
I was wondering if there are other best practices to solve this problem.我想知道是否有其他最佳实践来解决这个问题。 If not, I was also wondering how I can dynamically activate/deactive the @KafkaEventListener
for the DLT (as you don't want to have this listener all the time up)如果没有,我还想知道如何动态激活/停用 DLT 的@KafkaEventListener
(因为您不想一直使用此侦听器)
Thanks for your feedback!感谢您的反馈意见!
Jochen约臣
Solution number 2 looks perfect to me.解决方案 2 对我来说看起来很完美。
I was also wondering how I can dynamically activate/deactive the @KafkaEventListener for the DLT (as you don't want to have this listener all the time up)我还想知道如何动态激活/停用 DLT 的 @KafkaEventListener(因为您不想一直使用此侦听器)
You can use the @KafkaListener property autoStartup, introduced since 2.2.您可以使用自 2.2 以来引入的 @KafkaListener 属性 autoStartup。
@Autowired
private KafkaListenerEndpointRegistry registry;
@KafkaListener(id = "123", topics = "XXX.DLT", autoStartup = "true"){
//do your processing
}
//After you are done
registry.getListenerContainer("123").stop();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.