Class DefaultDestinationTopicResolver
java.lang.Object
org.springframework.kafka.listener.KafkaExceptionLogLevelAware
org.springframework.kafka.listener.ExceptionClassifier
org.springframework.kafka.retrytopic.DefaultDestinationTopicResolver
- All Implemented Interfaces:
EventListener
,Aware
,ApplicationContextAware
,ApplicationListener<ContextRefreshedEvent>
,DestinationTopicContainer
,DestinationTopicResolver
public class DefaultDestinationTopicResolver
extends ExceptionClassifier
implements DestinationTopicResolver, ApplicationListener<ContextRefreshedEvent>, ApplicationContextAware
Default implementation of the
DestinationTopicResolver
interface.
The container is closed when a ContextRefreshedEvent
is received
and no more destinations can be added after that.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell, Yvette Quinby, Adrian Chlebosz
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
-
Constructor Summary
ConstructorDescriptionConstructs an instance with a default clock.Constructs an instance with the given clock. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDestinationTopics
(String mainListenerId, List<DestinationTopic> destinationsToAdd) Adds the provided destination topics to the container.getDestinationTopicByName
(String mainListenerId, String topic) Returns theDestinationTopic
instance registered for that topic.Returns theDestinationTopic
instance registered as DLT for the given topic taking into consideration the exception thrown, or null if none is found.getNextDestinationTopicFor
(String mainListenerId, String topic) Returns theDestinationTopic
instance registered as the next destination topic in the chain for the given topic.boolean
Return true if the application context is refreshed.void
resolveDestinationTopic
(String mainListenerId, String topic, Integer attempt, Exception e, long originalTimestamp) Resolves the destination topic for the failed message.void
setApplicationContext
(ApplicationContext applicationContext) Methods inherited from class org.springframework.kafka.listener.ExceptionClassifier
addNotRetryableExceptions, addRetryableExceptions, defaultFalse, defaultFalse, defaultFatalExceptionsList, getClassifier, notRetryable, removeClassification, setClassifications
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
Methods inherited from interface org.springframework.kafka.retrytopic.DestinationTopicContainer
getDltFor
-
Constructor Details
-
DefaultDestinationTopicResolver
Constructs an instance with the given clock.- Parameters:
clock
- the clock to be used for time-based operations such as verifying timeouts.- Since:
- 2.9
-
DefaultDestinationTopicResolver
public DefaultDestinationTopicResolver()Constructs an instance with a default clock.- Since:
- 2.9
-
-
Method Details
-
resolveDestinationTopic
public DestinationTopic resolveDestinationTopic(String mainListenerId, String topic, Integer attempt, Exception e, long originalTimestamp) Description copied from interface:DestinationTopicResolver
Resolves the destination topic for the failed message.- Specified by:
resolveDestinationTopic
in interfaceDestinationTopicResolver
- Parameters:
mainListenerId
- the listener id.topic
- the current topic for the message.attempt
- the number of processing attempts already made for that message.e
- the exception the message processing has thrownoriginalTimestamp
- the time when the first attempt to process the message threw an exception.- Returns:
- the
DestinationTopic
for the given parameters.
-
getDestinationTopicByName
Description copied from interface:DestinationTopicContainer
Returns theDestinationTopic
instance registered for that topic.- Specified by:
getDestinationTopicByName
in interfaceDestinationTopicContainer
- Parameters:
mainListenerId
- the listener id.topic
- the topic name of the DestinationTopic to be returned.- Returns:
- the DestinationTopic instance registered for that topic.
-
getDltFor
Description copied from interface:DestinationTopicContainer
Returns theDestinationTopic
instance registered as DLT for the given topic taking into consideration the exception thrown, or null if none is found.- Specified by:
getDltFor
in interfaceDestinationTopicContainer
- Parameters:
mainListenerId
- the listener id.topicName
- the topic name for which to look the DLT fore
- the exception which is being handled- Returns:
- The
DestinationTopic
instance corresponding to the DLT.
-
getNextDestinationTopicFor
Description copied from interface:DestinationTopicContainer
Returns theDestinationTopic
instance registered as the next destination topic in the chain for the given topic. Note that this might not correspond to the actual next topic a message will be forwarded to, since that depends on different factors. If you need to find out the exact next topic for a message use theDestinationTopicResolver.resolveDestinationTopic(String, String, Integer, Exception, long)
method instead.- Specified by:
getNextDestinationTopicFor
in interfaceDestinationTopicContainer
- Parameters:
mainListenerId
- the listener id.topic
- the topic name of the DestinationTopic to be returned.- Returns:
- the next DestinationTopic in the chain registered for that topic.
-
addDestinationTopics
Description copied from interface:DestinationTopicContainer
Adds the provided destination topics to the container.- Specified by:
addDestinationTopics
in interfaceDestinationTopicContainer
- Parameters:
mainListenerId
- the listener id.destinationsToAdd
- theDestinationTopic
list to add.
-
onApplicationEvent
- Specified by:
onApplicationEvent
in interfaceApplicationListener<ContextRefreshedEvent>
-
isContextRefreshed
public boolean isContextRefreshed()Return true if the application context is refreshed.- Returns:
- true if refreshed.
- Since:
- 2.7.8
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-