1

I am using spring-cloud-stream-binder-kafka and have implemented stateful retry using DefaultErrorHandler, I found that by enabling deliveryAttemptHeader of container properties I can access the retry count or deliveryAttempt count from message header but I am not able to enable it.

I tried to set the value to true as below

@Bean
  public ContainerCustomizer<String, Message, ConcurrentMessageListenerContainer<String, Message>> containerCustomizer(
      ConcurrentKafkaListenerContainerFactory<String, Message> factory) {
    ContainerCustomizer<String, Message, ConcurrentMessageListenerContainer<String, Message>> custCustomizer = container -> {
      container.getContainerProperties().setDeliveryAttemptHeader(true);
    };
    factory.setContainerCustomizer(custCustomizer);
    return custCustomizer;
  }

With this configuration when I start the application and debug KafkaMessageListenerContainer.java#L1078 I still see that deliveryAttemptHeader is disabled, and also the ContainerCustomizer instance that I have created is also not getting called.

Chintan Radia
  • 236
  • 2
  • 9

1 Answers1

0

spring-cloud-stream does not use Boot's container factory; use its ListenerContainerCustomizer instead.

https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_advanced_consumer_configuration

Gary Russell
  • 166,535
  • 14
  • 146
  • 179