【问题标题】:DLT message consumptionDLT 消息消费
【发布时间】:2021-12-02 20:55:53
【问题描述】:

我们使用的是 Spring kafka 2.7 非阻塞重试机制。在 Spring Kafka 重试机制期间,kafka 监听器消费来自 main topic、retry topic 和 DLT Topic 的消息, 我们希望侦听器仅从主主题和重试主题中消费。

有没有简单的设置方法?

因为我们不希望同一个消费者处理 DLT 消息。 DLT 也将被另一个进程使用,以发送请求通知。

// our configuration

 @Bean
  public ConcurrentKafkaListenerContainerFactory<String, Object> kafkaListenerContainerFactory() {

    ConcurrentKafkaListenerContainerFactory<String, Object> factory
        = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    return factory;
  }


@Bean
  public RetryTopicConfiguration retryTopicConfiguration(KafkaTemplate<String, Object> template) {

    List<Class<? extends Throwable>> throwableList = Arrays.asList(IllegalArgumentException.class,
        IllegalAccessException.class);

    return RetryTopicConfigurationBuilder
        .newInstance()
        .dltHandlerMethod(XYZ.class, "xyz")
        .exponentialBackoff(delayMs, backoffMultiplier, maxIntervalInMs)
        .maxAttempts(retryAttempt)
        .notRetryOn(throwableList)
        .doNotAutoCreateRetryTopics()
        .listenerFactory(kafkaListenerContainerFactory())
        .setTopicSuffixingStrategy(TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
        .create(template);
  }

【问题讨论】:

  • @GaryRussell : 请帮忙

标签: java spring spring-boot apache-kafka spring-kafka


【解决方案1】:

只需删除.dltHandlerMethod(XYZ.class, "xyz")

编辑

这仍然会创建一个默认的 DLT 处理程序,它只会记录记录。

您可以在“其他”消费者中使用不同的组,也可以手动启动容器(DLT 容器除外)。

@KafkaListener上设置autoStartup="false";然后添加这个...

@Bean
ApplicationRunner runner(KafkaListenerEndpointRegistry registry) {
    return args -> {
        registry.getListenerContainerIds().forEach(id -> {
            if (!id.endsWith("-dlt")) {
                registry.getListenerContainer(id).start();
            }
        });
    };
}

【讨论】:

  • 感谢加里的回复。如果我们删除上述方法,默认的 DLT 处理程序方法将被称为移动偏移量的结果。我们想要配置 dlt,但它不应该被我们和 spring 默认的 dlt 记录器使用。我们希望在另一个特定的侦听器中侦听同一组的 dlt 主题是我们的要求。
  • 目前无法做到这一点 - 您可以为其他消费者使用不同的组,或者查看其他解决方法的编辑。
  • github.com/spring-projects/spring-kafka/commit/… - 这将在 2.8 中可用(下个月到期)。
猜你喜欢
  • 2020-11-02
  • 2015-11-25
  • 1970-01-01
  • 2017-09-23
  • 1970-01-01
  • 2022-06-15
  • 2020-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多