Class AbstractRoutingAmqpConnectionFactory
java.lang.Object
org.springframework.amqp.rabbitmq.client.AbstractRoutingAmqpConnectionFactory
- All Implemented Interfaces:
AmqpConnectionFactory,RoutingAmqpConnectionFactory,InitializingBean
- Direct Known Subclasses:
SimpleRoutingAmqpConnectionFactory
public abstract class AbstractRoutingAmqpConnectionFactory
extends Object
implements AmqpConnectionFactory, RoutingAmqpConnectionFactory, InitializingBean
Abstract
AmqpConnectionFactory implementation that routes getConnection()
calls to one of various target AmqpConnectionFactories based
on a lookup key. The latter is usually (but not necessarily) determined through some
thread-bound context.- Since:
- 4.2
- Author:
- Robin Collard
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTargetConnectionFactory(Object key, AmqpConnectionFactory connectionFactory) Add the givenAmqpConnectionFactoryand associate it with the given lookup key.voidprotected abstract @Nullable ObjectDetermine the current lookup key.protected AmqpConnectionFactoryRetrieve the current targetAmqpConnectionFactory.com.rabbitmq.client.amqp.Connection@Nullable AmqpConnectionFactoryReturn theAmqpConnectionFactorybound to given lookup key, ornullif one does not exist.protected boolean@Nullable AmqpConnectionFactoryRemove theAmqpConnectionFactoryassociated with the given lookup key and return it.voidsetDefaultTargetConnectionFactory(AmqpConnectionFactory defaultTargetConnectionFactory) Specify the default targetAmqpConnectionFactory, if any.voidsetLenientFallback(boolean lenientFallback) Specify whether to apply a lenient fallback to the defaultAmqpConnectionFactoryif no specificAmqpConnectionFactorycould be found for the current lookup key.voidsetTargetConnectionFactories(Map<Object, AmqpConnectionFactory> targetConnectionFactories) Specify the map of targetAmqpConnectionFactories, with the lookup key as key.
-
Constructor Details
-
AbstractRoutingAmqpConnectionFactory
public AbstractRoutingAmqpConnectionFactory()
-
-
Method Details
-
setTargetConnectionFactories
public void setTargetConnectionFactories(Map<Object, AmqpConnectionFactory> targetConnectionFactories) Specify the map of targetAmqpConnectionFactories, with the lookup key as key.The key can be of arbitrary type; this class implements the generic lookup process only. The concrete key representation will be handled by
determineCurrentLookupKey().- Parameters:
targetConnectionFactories- the target connection factories and lookup keys.
-
setDefaultTargetConnectionFactory
Specify the default targetAmqpConnectionFactory, if any.This
AmqpConnectionFactorywill be used as target if none of the keyedtargetConnectionFactoriesmatch thedetermineCurrentLookupKey()current lookup key.- Parameters:
defaultTargetConnectionFactory- the default target connection factory.
-
setLenientFallback
public void setLenientFallback(boolean lenientFallback) Specify whether to apply a lenient fallback to the defaultAmqpConnectionFactoryif no specificAmqpConnectionFactorycould be found for the current lookup key.Default is "true", accepting lookup keys without a corresponding entry in the
targetConnectionFactories- simply falling back to the defaultAmqpConnectionFactoryin that case.Switch this flag to "false" if you would prefer the fallback to only apply if the lookup key was
null. Lookup keys without anAmqpConnectionFactoryentry will then lead to anIllegalStateException.- Parameters:
lenientFallback- true to fall back to the default, if specified.- See Also:
-
isLenientFallback
protected boolean isLenientFallback() -
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
getConnection
public com.rabbitmq.client.amqp.Connection getConnection()- Specified by:
getConnectionin interfaceAmqpConnectionFactory
-
determineTargetConnectionFactory
Retrieve the current targetAmqpConnectionFactory. Determine thecurrent lookup key, perform a lookup in thetargetConnectionFactoriesmap, fall back to the specifieddefaultTargetConnectionFactoryif necessary.- Returns:
- the connection factory.
- See Also:
-
getTargetConnectionFactory
Description copied from interface:RoutingAmqpConnectionFactoryReturn theAmqpConnectionFactorybound to given lookup key, ornullif one does not exist.- Specified by:
getTargetConnectionFactoryin interfaceRoutingAmqpConnectionFactory- Parameters:
key- the lookup key to which theAmqpConnectionFactoryis bound.- Returns:
- the
AmqpConnectionFactorybound to the given lookup key, ornullif one does not exist.
-
addTargetConnectionFactory
Add the givenAmqpConnectionFactoryand associate it with the given lookup key.- Parameters:
key- the lookup key.connectionFactory- theAmqpConnectionFactory.
-
removeTargetConnectionFactory
Remove theAmqpConnectionFactoryassociated with the given lookup key and return it.- Parameters:
key- the lookup key.- Returns:
- the
AmqpConnectionFactorythat was removed.
-
determineCurrentLookupKey
Determine the current lookup key. This will typically be implemented to check a thread-bound context.- Returns:
- the lookup key.
-