Class AbstractMappingMessageRouter
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.router.AbstractMessageRouter
org.springframework.integration.router.AbstractMappingMessageRouter
- All Implemented Interfaces:
- org.reactivestreams.Subscriber<Message<?>>,- Aware,- BeanFactoryAware,- BeanNameAware,- DisposableBean,- InitializingBean,- ApplicationContextAware,- Ordered,- ExpressionCapable,- Orderable,- IntegrationPattern,- MessageRouter,- NamedComponent,- IntegrationManagement,- MappingMessageRouterManagement,- TrackableComponent,- MessageHandler,- reactor.core.CoreSubscriber<Message<?>>
- Direct Known Subclasses:
- ErrorMessageExceptionTypeRouter,- ExpressionEvaluatingRouter,- HeaderValueRouter,- MethodInvokingRouter,- PayloadTypeRouter,- XPathRouter
public abstract class AbstractMappingMessageRouter
extends AbstractMessageRouter
implements MappingMessageRouterManagement
Base class for all Message Routers that support mapping from arbitrary String values
 to Message Channel names.
- Since:
- 2.1
- Author:
- Mark Fisher, Oleg Zhurakousky, Gunnar Hillert, Gary Russell, Artem Bilan, Trung Pham
- 
Nested Class SummaryNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagementIntegrationManagement.ManagementOverrides
- 
Field SummaryFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagementMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected Collection<MessageChannel>determineTargetChannels(Message<?> message) Subclasses must implement this method to return a Collection of zero or more MessageChannels to which the given Message should be routed.getChannelKeys(Message<?> message) Subclasses must implement this method to return the channel keys.Returns an unmodifiable version of the channel mappings.Provide a collection of channel names to which we have routed messages where the channel was not explicitly mapped.protected voidonInit()Subclasses may implement this for initialization logic.voidRemove a channel mapping for the given key if present.voidreplaceChannelMappings(Properties channelMappings) Convenience method allowing conversion of a list of mappings in a control-bus message.voidsetChannelKeyFallback(boolean channelKeyFallback) When true (default), if a resolved channel key does not exist in the channel map, the key itself is used as the channel name, which we will attempt to resolve to a channel.voidsetChannelMapping(String key, String channelName) Add a channel mapping from the provided key to channel name.voidsetChannelMappings(Map<String, String> channelMappings) Provide mappings from channel keys to channel names.voidsetDefaultOutputChannel(MessageChannel defaultOutputChannel) Set the default channel where Messages should be sent if channel resolution fails to return any channels.voidsetDefaultOutputChannelName(String defaultOutputChannelName) Set the default channel where Messages should be sent if channel resolution fails to return any channels.voidsetDynamicChannelLimit(int dynamicChannelLimit) Set a limit for how many dynamic channels are retained (for reporting purposes).voidSpecify a prefix to be added to each channel name prior to resolution.voidsetResolutionRequired(boolean resolutionRequired) Specify whether this router should ignore any failure to resolve a channel name to an actual MessageChannel instance when delegating to the ChannelResolver strategy.voidSpecify a suffix to be added to each channel name prior to resolution.Methods inherited from class org.springframework.integration.router.AbstractMessageRoutergetComponentType, getDefaultOutputChannel, getIntegrationPatternType, getMessagingTemplate, getRequiredConversionService, handleMessageInternal, setApplySequence, setIgnoreSendFailures, setSendTimeoutMethods inherited from class org.springframework.integration.handler.AbstractMessageHandlerhandleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupportbuildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscribercurrentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagementgetThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponentgetBeanName, getComponentName
- 
Constructor Details- 
AbstractMappingMessageRouterpublic AbstractMappingMessageRouter()
 
- 
- 
Method Details- 
setChannelMappingsProvide mappings from channel keys to channel names. Channel names will be resolved by theDestinationResolver.- Specified by:
- setChannelMappingsin interface- MappingMessageRouterManagement
- Parameters:
- channelMappings- The channel mappings.
 
- 
setPrefixSpecify a prefix to be added to each channel name prior to resolution.- Parameters:
- prefix- The prefix.
 
- 
setSuffixSpecify a suffix to be added to each channel name prior to resolution.- Parameters:
- suffix- The suffix.
 
- 
setResolutionRequiredpublic void setResolutionRequired(boolean resolutionRequired) Specify whether this router should ignore any failure to resolve a channel name to an actual MessageChannel instance when delegating to the ChannelResolver strategy.- Parameters:
- resolutionRequired- true if resolution is required.
 
- 
setChannelKeyFallbackpublic void setChannelKeyFallback(boolean channelKeyFallback) When true (default), if a resolved channel key does not exist in the channel map, the key itself is used as the channel name, which we will attempt to resolve to a channel. Set tofalseto disable this feature. This could be useful to prevent malicious actors from generating a message that could cause the message to be routed to an unexpected channel, such as one upstream of the router, which would cause a stack overflow.- Parameters:
- channelKeyFallback- false to disable the fallback.
- Since:
- 5.2
 
- 
setDefaultOutputChannelSet the default channel where Messages should be sent if channel resolution fails to return any channels. It also setschannelKeyFallbacktofalseto avoid an attempt to resolve a channel from its key, but instead send the message directly to this channel. IfchannelKeyFallbackis set explicitly totrue, the logic depends on theresolutionRequiredoption (trueby default), and therefore a fallback to this default output channel may never happen. The configuration where a default output channel is present andresolutionRequiredandchannelKeyFallbackare set totrueis rejected since it leads to ambiguity.- Overrides:
- setDefaultOutputChannelin class- AbstractMessageRouter
- Parameters:
- defaultOutputChannel- The default output channel.
- Since:
- 6.0
- See Also:
 
- 
setDefaultOutputChannelNameSet the default channel where Messages should be sent if channel resolution fails to return any channels. It also setschannelKeyFallbacktofalseto avoid an attempt to resolve a channel from its key, but instead send the message directly to this channel. IfchannelKeyFallbackis set explicitly totrue, the logic depends on theresolutionRequiredoption (trueby default), and therefore a fallback to this default output channel may never happen. The configuration where a default output channel is present andresolutionRequiredandchannelKeyFallbackare set totrueis rejected since it leads to ambiguity.- Overrides:
- setDefaultOutputChannelNamein class- AbstractMessageRouter
- Parameters:
- defaultOutputChannelName- the name of the channel bean for default output.
- Since:
- 6.0
- See Also:
 
- 
setDynamicChannelLimitpublic void setDynamicChannelLimit(int dynamicChannelLimit) Set a limit for how many dynamic channels are retained (for reporting purposes). When the limit is exceeded, the oldest channel is discarded.NOTE: this does not affect routing, just the reporting which dynamically resolved channels have been routed to. Default 100.- Parameters:
- dynamicChannelLimit- the limit.
- See Also:
 
- 
getChannelMappingsReturns an unmodifiable version of the channel mappings. This is intended for use by subclasses only.- Specified by:
- getChannelMappingsin interface- MappingMessageRouterManagement
- Returns:
- The channel mappings.
 
- 
setChannelMappingAdd a channel mapping from the provided key to channel name.- Specified by:
- setChannelMappingin interface- MappingMessageRouterManagement
- Parameters:
- key- The key.
- channelName- The channel name.
 
- 
removeChannelMappingRemove a channel mapping for the given key if present.- Specified by:
- removeChannelMappingin interface- MappingMessageRouterManagement
- Parameters:
- key- The key.
 
- 
getDynamicChannelNamesDescription copied from interface:MappingMessageRouterManagementProvide a collection of channel names to which we have routed messages where the channel was not explicitly mapped.Implementations may choose to return only the most recent channel names. - Specified by:
- getDynamicChannelNamesin interface- MappingMessageRouterManagement
- Returns:
- a collection of channel names to which we have routed messages where the channel was not explicitly mapped.
 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- AbstractMessageRouter
 
- 
determineTargetChannelsDescription copied from class:AbstractMessageRouterSubclasses must implement this method to return a Collection of zero or more MessageChannels to which the given Message should be routed.- Specified by:
- determineTargetChannelsin class- AbstractMessageRouter
- Parameters:
- message- The message.
- Returns:
- The collection of message channels.
 
- 
getChannelKeysSubclasses must implement this method to return the channel keys. A "key" might be present in this router's "channelMappings", or it could be the channel's name or even the Message Channel instance itself.- Parameters:
- message- The message.
- Returns:
- The channel keys.
 
- 
replaceChannelMappingsConvenience method allowing conversion of a list of mappings in a control-bus message.This is intended to be called via a control-bus; keys and values that are not Strings will be ignored. Mappings must be delimited with newlines, for example: "@'myRouter.handler'.replaceChannelMappings('foo=qux \n baz=bar')".- Specified by:
- replaceChannelMappingsin interface- MappingMessageRouterManagement
- Parameters:
- channelMappings- The channel mappings.
- Since:
- 4.0
 
 
-