Class AbstractRoutingConnectionFactory
- All Implemented Interfaces:
- ConnectionFactory,- InitializingBean
ConnectionFactory implementation that routes
 create() calls to one of various target
 factories based on a lookup key.
 The latter is typically (but not necessarily) determined from some
 subscriber context.
 Allows to configure a default target ConnectionFactory as a fallback.
 
Calls to getMetadata() are routed to the
 default ConnectionFactory
 if configured.
- Since:
- 5.3
- Author:
- Mark Paluch, Jens Schauder
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidDelegates toinitialize().reactor.core.publisher.Mono<Connection>create()protected abstract reactor.core.publisher.Mono<Object>Determine the current lookup key.protected reactor.core.publisher.Mono<ConnectionFactory>Retrieve the current targetConnectionFactory.voidInitialize the internal state of thisAbstractRoutingConnectionFactoryby resolving the configured target ConnectionFactories.protected ConnectionFactoryresolveSpecifiedConnectionFactory(Object connectionFactory) Resolve the specified connection factory object into aConnectionFactoryinstance.protected ObjectresolveSpecifiedLookupKey(Object lookupKey) Resolve the given lookup key object, as specified in thetargetConnectionFactoriesmap, into the actual lookup key to be used for matching with thecurrent lookup key.voidsetConnectionFactoryLookup(ConnectionFactoryLookup connectionFactoryLookup) Set theConnectionFactoryLookupimplementation to use for resolving connection factory name Strings in thetargetConnectionFactoriesmap.voidsetDefaultTargetConnectionFactory(Object defaultTargetConnectionFactory) Specify the default targetConnectionFactory, if any.voidsetLenientFallback(boolean lenientFallback) Specify whether to apply a lenient fallback to the defaultConnectionFactoryif no specificConnectionFactorycould be found for the current lookup key.voidsetTargetConnectionFactories(Map<?, ?> targetConnectionFactories) Specify the map of targetConnectionFactories, with the lookup key as key.
- 
Constructor Details- 
AbstractRoutingConnectionFactorypublic AbstractRoutingConnectionFactory()
 
- 
- 
Method Details- 
setTargetConnectionFactoriesSpecify the map of targetConnectionFactories, with the lookup key as key. The mapped value can either be a correspondingConnectionFactoryinstance or a connection factory name String (to be resolved via aConnectionFactoryLookup).The key can be of arbitrary type; this class implements the generic lookup process only. The concrete key representation will be handled by resolveSpecifiedLookupKey(Object)anddetermineCurrentLookupKey().
- 
setDefaultTargetConnectionFactorySpecify the default targetConnectionFactory, if any.The mapped value can either be a corresponding ConnectionFactoryinstance or a connection factory nameString(to be resolved via aConnectionFactoryLookup).This ConnectionFactorywill be used as target if none of the keyedtargetConnectionFactoriesmatch thecurrent lookup key.
- 
setLenientFallbackpublic void setLenientFallback(boolean lenientFallback) Specify whether to apply a lenient fallback to the defaultConnectionFactoryif no specificConnectionFactorycould be found for the current lookup key.Default is true, accepting lookup keys without a corresponding entry in the targetConnectionFactorymap - simply falling back to the defaultConnectionFactoryin that case.Switch this flag to falseif you would prefer the fallback to only apply when no lookup key was emitted. Lookup keys without aConnectionFactoryentry will then lead to anIllegalStateException.
- 
setConnectionFactoryLookupSet theConnectionFactoryLookupimplementation to use for resolving connection factory name Strings in thetargetConnectionFactoriesmap.
- 
afterPropertiesSetpublic void afterPropertiesSet()Delegates toinitialize().- Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
initializepublic void initialize()Initialize the internal state of thisAbstractRoutingConnectionFactoryby resolving the configured target ConnectionFactories.- Throws:
- IllegalArgumentException- if the target ConnectionFactories have not been configured
- Since:
- 6.1
- See Also:
 
- 
resolveSpecifiedLookupKeyResolve the given lookup key object, as specified in thetargetConnectionFactoriesmap, into the actual lookup key to be used for matching with thecurrent lookup key.The default implementation simply returns the given key as-is. - Parameters:
- lookupKey- the lookup key object as specified by the user
- Returns:
- the lookup key as needed for matching.
 
- 
resolveSpecifiedConnectionFactoryprotected ConnectionFactory resolveSpecifiedConnectionFactory(Object connectionFactory) throws IllegalArgumentException Resolve the specified connection factory object into aConnectionFactoryinstance.The default implementation handles ConnectionFactoryinstances and connection factory names (to be resolved via aConnectionFactoryLookup).- Parameters:
- connectionFactory- the connection factory value object as specified in the- targetConnectionFactoriesmap
- Returns:
- the resolved ConnectionFactory(nevernull)
- Throws:
- IllegalArgumentException- in case of an unsupported value type
 
- 
create- Specified by:
- createin interface- ConnectionFactory
 
- 
getMetadata- Specified by:
- getMetadatain interface- ConnectionFactory
 
- 
determineTargetConnectionFactoryRetrieve the current targetConnectionFactory. Determines thecurrent lookup key, performs a lookup in thetargetConnectionFactoriesmap, falls back to the specifieddefault target ConnectionFactoryif necessary.- Returns:
- Monothat emits the current- ConnectionFactoryas per- determineCurrentLookupKey()
- See Also:
 
- 
determineCurrentLookupKeyDetermine the current lookup key. This will typically be implemented to check a subscriber context. Allows for arbitrary keys. The returned key needs to match the stored lookup key type, as resolved by theresolveSpecifiedLookupKey(java.lang.Object)method.- Returns:
- Monoemitting the lookup key. May complete without emitting a value if no lookup key available
 
 
-