0

I have three spring @KafkaListeners, all consuming from the same topic, but I need to have different retry attempts for each listener which results in having different RetryPolicy I guess.

I am on version 2.7.11 right now; Should I define three different listener container Factories as well or there is a way to handle them on the same listener container factory?

sansari
  • 558
  • 1
  • 7
  • 17

1 Answers1

0

RetryTemplate in the container factory is deprecated now that error handlers support backoffs and exception classification.

https://github.com/spring-projects/spring-kafka/issues/1886

You can add a container customizer to the factory and set a different error handler (with different back offs) for each container.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Could you please clarify on the difference between factory and container? I have a `ConcurrentKafkaListenerContainerFactory` in our kafka library and created another in the application myself. I created a customizer like this https://stackoverflow.com/questions/62456540/when-using-kafkalistener-in-springboot-how-to-set-idlebetweenpolls and I get the error that there are two factories. How I configure two containers within a factory? – sansari Mar 29 '22 at 13:32
  • 1
    The factory creates a container for each of its listeners. If you have two or more factories; there are several solutions; you can mark one of them as `@Primary`; you can change the constructor parameter name to match the bean name of one of your factories; you can change the constructor to receive a `List` of factories to get them all. – Gary Russell Mar 29 '22 at 13:49