Class AbstractRoutingConnectionFactory
- java.lang.Object
-
- org.springframework.amqp.rabbit.connection.AbstractRoutingConnectionFactory
-
- All Implemented Interfaces:
ConnectionFactory,RoutingConnectionFactory,InitializingBean
- Direct Known Subclasses:
SimpleRoutingConnectionFactory
public abstract class AbstractRoutingConnectionFactory extends Object implements ConnectionFactory, RoutingConnectionFactory, InitializingBean
AbstractConnectionFactoryimplementation that routescreateConnection()calls to one of various target ConnectionFactories based on a lookup key. The latter is usually (but not necessarily) determined through some thread-bound context.- Since:
- 1.3
- Author:
- Artem Bilan, Josh Chappelle, Gary Russell
-
-
Constructor Summary
Constructors Constructor Description AbstractRoutingConnectionFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddConnectionListener(ConnectionListener listener)protected voidaddTargetConnectionFactory(Object key, ConnectionFactory connectionFactory)Adds the givenConnectionFactoryand associates it with the given lookup key.voidafterPropertiesSet()voidclearConnectionListeners()ConnectioncreateConnection()protected abstract ObjectdetermineCurrentLookupKey()Determine the current lookup key.protected ConnectionFactorydetermineTargetConnectionFactory()Retrieve the current targetConnectionFactory.StringgetHost()intgetPort()ConnectionFactorygetTargetConnectionFactory(Object key)Returns theConnectionFactorybound to given lookup key, or null if one does not exist.StringgetUsername()StringgetVirtualHost()booleanisLenientFallback()booleanisPublisherConfirms()Return true if publisher confirms are enabled.booleanisPublisherReturns()Return true if publisher returns are enabled.booleanremoveConnectionListener(ConnectionListener listener)protected ConnectionFactoryremoveTargetConnectionFactory(Object key)Removes theConnectionFactoryassociated with the given lookup key and returns it.voidsetDefaultTargetConnectionFactory(ConnectionFactory 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<Object,ConnectionFactory> targetConnectionFactories)Specify the map of target ConnectionFactories, with the lookup key as key.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.springframework.amqp.rabbit.connection.ConnectionFactory
getPublisherConnectionFactory, isSimplePublisherConfirms
-
-
-
-
Method Detail
-
setTargetConnectionFactories
public void setTargetConnectionFactories(Map<Object,ConnectionFactory> targetConnectionFactories)
Specify the map of target ConnectionFactories, 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
public void setDefaultTargetConnectionFactory(ConnectionFactory defaultTargetConnectionFactory)
Specify the default targetConnectionFactory, if any.This
ConnectionFactorywill 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 defaultConnectionFactoryif no specificConnectionFactorycould 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 defaultConnectionFactoryin 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 aConnectionFactoryentry will then lead to anIllegalStateException.- Parameters:
lenientFallback- true to fall back to the default, if specified.- See Also:
setTargetConnectionFactories(java.util.Map<java.lang.Object, org.springframework.amqp.rabbit.connection.ConnectionFactory>),setDefaultTargetConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory),determineCurrentLookupKey()
-
isLenientFallback
public boolean isLenientFallback()
-
isPublisherConfirms
public boolean isPublisherConfirms()
Description copied from interface:ConnectionFactoryReturn true if publisher confirms are enabled.- Specified by:
isPublisherConfirmsin interfaceConnectionFactory- Returns:
- publisherConfirms.
-
isPublisherReturns
public boolean isPublisherReturns()
Description copied from interface:ConnectionFactoryReturn true if publisher returns are enabled.- Specified by:
isPublisherReturnsin interfaceConnectionFactory- Returns:
- publisherReturns.
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception- Specified by:
afterPropertiesSetin interfaceInitializingBean- Throws:
Exception
-
createConnection
public Connection createConnection() throws AmqpException
- Specified by:
createConnectionin interfaceConnectionFactory- Throws:
AmqpException
-
determineTargetConnectionFactory
protected ConnectionFactory determineTargetConnectionFactory()
Retrieve the current targetConnectionFactory. Determines thecurrent lookup key, performs a lookup in thetargetConnectionFactoriesmap, falls back to the specifieddefaultTargetConnectionFactoryif necessary.- Returns:
- The connection factory.
- See Also:
determineCurrentLookupKey()
-
addConnectionListener
public void addConnectionListener(ConnectionListener listener)
- Specified by:
addConnectionListenerin interfaceConnectionFactory
-
removeConnectionListener
public boolean removeConnectionListener(ConnectionListener listener)
- Specified by:
removeConnectionListenerin interfaceConnectionFactory
-
clearConnectionListeners
public void clearConnectionListeners()
- Specified by:
clearConnectionListenersin interfaceConnectionFactory
-
getHost
public String getHost()
- Specified by:
getHostin interfaceConnectionFactory
-
getPort
public int getPort()
- Specified by:
getPortin interfaceConnectionFactory
-
getVirtualHost
public String getVirtualHost()
- Specified by:
getVirtualHostin interfaceConnectionFactory
-
getUsername
public String getUsername()
- Specified by:
getUsernamein interfaceConnectionFactory
-
getTargetConnectionFactory
public ConnectionFactory getTargetConnectionFactory(Object key)
Description copied from interface:RoutingConnectionFactoryReturns theConnectionFactorybound to given lookup key, or null if one does not exist.- Specified by:
getTargetConnectionFactoryin interfaceRoutingConnectionFactory- Parameters:
key- The lookup key to which theConnectionFactoryis bound- Returns:
- the
ConnectionFactorybound to the given lookup key, or null if one does not exist
-
addTargetConnectionFactory
protected void addTargetConnectionFactory(Object key, ConnectionFactory connectionFactory)
Adds the givenConnectionFactoryand associates it with the given lookup key.- Parameters:
key- the lookup key.connectionFactory- theConnectionFactory.
-
removeTargetConnectionFactory
protected ConnectionFactory removeTargetConnectionFactory(Object key)
Removes theConnectionFactoryassociated with the given lookup key and returns it.- Parameters:
key- the lookup key- Returns:
- the
ConnectionFactorythat was removed
-
-