This version is still in development and is not considered stable yet. For the latest stable version, please use Spring for Apache Kafka 3.2.4! |
Specifying a ListenerContainerFactory
By default the RetryTopic configuration will use the provided factory from the @KafkaListener
annotation, but you can specify a different one to be used to create the retry topic and dlt listener containers.
For the @RetryableTopic
annotation you can provide the factory’s bean name, and using the RetryTopicConfiguration
bean you can either provide the bean name or the instance itself.
@RetryableTopic(listenerContainerFactory = "my-retry-topic-factory")
@KafkaListener(topics = "my-annotated-topic")
public void processMessage(MyPojo message) {
// ... message processing
}
@Bean
public RetryTopicConfiguration myRetryTopic(KafkaTemplate<Integer, MyPojo> template,
ConcurrentKafkaListenerContainerFactory<Integer, MyPojo> factory) {
return RetryTopicConfigurationBuilder
.newInstance()
.listenerFactory(factory)
.create(template);
}
@Bean
public RetryTopicConfiguration myOtherRetryTopic(KafkaTemplate<Integer, MyPojo> template) {
return RetryTopicConfigurationBuilder
.newInstance()
.listenerFactory("my-retry-topic-factory")
.create(template);
}
Since 2.8.3 you can use the same factory for retryable and non-retryable topics. |