简体   繁体   English

使用 Spring Kafka 处理死信主题的消息

[英]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:我们看到的可能性:

  • write a small application that copies the messages from the DLT to the original topic编写一个小应用程序,将消息从 DLT 复制到原始主题
  • add a second @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.

相关问题 无法从 Kafka 中的消费者向死信主题发送消息 - Unable to send messages to dead letter topic from consumer in Kafka 将邮件从死信移回主题 - Moving messages from dead letter back to topic Kafka 死信队列,仅用于具有相同密钥的消息 - Kafka dead letter queue, for messages with same key only 延迟处理死信队列 - Handling dead letter queue with delay Spring Kafka多个使用者针对单个主题消耗不同的消息 - Spring Kafka multiple consumer for single topic consume different messages 使用 Spring Kafka 从单个主题反序列化不同的消息(使用共享数据) - Deserializing different messages (With shared data) from single topic with Spring Kafka Spring Kafka - 使用任何主题的分区的最后 N 条消息 - Spring Kafka - Consume last N messages for partitions(s) for any topic Spring Kafka Binder 没有收到任何消息但已连接到主题 - Spring Kafka Binder not receiving any messages but is connected to the topic 交易失败时无法发布到死信主题 - Cannot publish to dead letter topic on transaction failed Spring AMQP-使用带有TTL的死信机制进行消息重新排队 - Spring AMQP - Message re queuing using dead letter mechanism with TTL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM