Class DefaultDestinationTopicResolver
- java.lang.Object
-
- org.springframework.kafka.listener.KafkaExceptionLogLevelAware
-
- org.springframework.kafka.listener.ExceptionClassifier
-
- org.springframework.kafka.retrytopic.DefaultDestinationTopicResolver
-
- All Implemented Interfaces:
java.util.EventListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>,DestinationTopicContainer,DestinationTopicResolver
public class DefaultDestinationTopicResolver extends ExceptionClassifier implements DestinationTopicResolver, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.context.ApplicationContextAware
Default implementation of theDestinationTopicResolverinterface. The container is closed when aContextRefreshedEventis received and no more destinations can be added after that.- Since:
- 2.7
- Author:
- Tomaz Fernandes, Gary Russell, Yvette Quinby
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultDestinationTopicResolver.DestinationTopicHolder
-
Constructor Summary
Constructors Constructor Description DefaultDestinationTopicResolver()Constructs an instance with a default clock.DefaultDestinationTopicResolver(java.time.Clock clock)Constructs an instance with the given clock.DefaultDestinationTopicResolver(java.time.Clock clock, org.springframework.context.ApplicationContext applicationContext)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDestinationTopics(java.util.List<DestinationTopic> destinationsToAdd)Adds the provided destination topics to the container.DestinationTopicgetDestinationTopicByName(java.lang.String topic)Returns theDestinationTopicinstance registered for that topic.DestinationTopicgetDltFor(java.lang.String topicName)Returns theDestinationTopicinstance registered as DLT for the given topic, or null if none is found.DestinationTopicgetNextDestinationTopicFor(java.lang.String topic)Returns theDestinationTopicinstance registered as the next destination topic in the chain for the given topic.booleanisContextRefreshed()Return true if the application context is refreshed.voidonApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)DestinationTopicresolveDestinationTopic(java.lang.String topic, java.lang.Integer attempt, java.lang.Exception e, long originalTimestamp)Resolves the destination topic for the failed message.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)-
Methods inherited from class org.springframework.kafka.listener.ExceptionClassifier
addNotRetryableExceptions, addRetryableExceptions, defaultFalse, defaultFatalExceptionsList, getClassifier, notRetryable, removeClassification, removeNotRetryableException, setClassifications
-
Methods inherited from class org.springframework.kafka.listener.KafkaExceptionLogLevelAware
getLogLevel, setLogLevel
-
-
-
-
Constructor Detail
-
DefaultDestinationTopicResolver
@Deprecated public DefaultDestinationTopicResolver(java.time.Clock clock, org.springframework.context.ApplicationContext applicationContext)Deprecated.
-
DefaultDestinationTopicResolver
public DefaultDestinationTopicResolver(java.time.Clock clock)
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 Detail
-
resolveDestinationTopic
public DestinationTopic resolveDestinationTopic(java.lang.String topic, java.lang.Integer attempt, java.lang.Exception e, long originalTimestamp)
Description copied from interface:DestinationTopicResolverResolves the destination topic for the failed message.- Specified by:
resolveDestinationTopicin interfaceDestinationTopicResolver- Parameters:
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
DestinationTopicfor the given parameters.
-
getDestinationTopicByName
public DestinationTopic getDestinationTopicByName(java.lang.String topic)
Description copied from interface:DestinationTopicContainerReturns theDestinationTopicinstance registered for that topic.- Specified by:
getDestinationTopicByNamein interfaceDestinationTopicContainer- Parameters:
topic- the topic name of the DestinationTopic to be returned.- Returns:
- the DestinationTopic instance registered for that topic.
-
getDltFor
@Nullable public DestinationTopic getDltFor(java.lang.String topicName)
Description copied from interface:DestinationTopicContainerReturns theDestinationTopicinstance registered as DLT for the given topic, or null if none is found.- Specified by:
getDltForin interfaceDestinationTopicContainer- Parameters:
topicName- the topic name for which to look the DLT for- Returns:
- The
DestinationTopicinstance corresponding to the DLT.
-
getNextDestinationTopicFor
public DestinationTopic getNextDestinationTopicFor(java.lang.String topic)
Description copied from interface:DestinationTopicContainerReturns theDestinationTopicinstance 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, Integer, Exception, long)method instead.- Specified by:
getNextDestinationTopicForin interfaceDestinationTopicContainer- Parameters:
topic- the topic name of the DestinationTopic to be returned.- Returns:
- the next DestinationTopic in the chain registered for that topic.
-
addDestinationTopics
public void addDestinationTopics(java.util.List<DestinationTopic> destinationsToAdd)
Description copied from interface:DestinationTopicContainerAdds the provided destination topics to the container.- Specified by:
addDestinationTopicsin interfaceDestinationTopicContainer- Parameters:
destinationsToAdd- theDestinationTopiclist to add.
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
-
isContextRefreshed
public boolean isContextRefreshed()
Return true if the application context is refreshed.- Returns:
- true if refreshed.
- Since:
- 2.7.8
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
-