public abstract class AbstractRoutingConnectionFactory extends Object implements ConnectionFactory, InitializingBean
ConnectionFactory implementation that routes createConnection()
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.| Constructor and Description |
|---|
AbstractRoutingConnectionFactory() |
| Modifier and Type | Method and Description |
|---|---|
void |
addConnectionListener(ConnectionListener listener) |
void |
afterPropertiesSet() |
void |
clearConnectionListeners() |
Connection |
createConnection() |
protected abstract Object |
determineCurrentLookupKey()
Determine the current lookup key.
|
protected ConnectionFactory |
determineTargetConnectionFactory()
Retrieve the current target
ConnectionFactory. |
String |
getHost() |
int |
getPort() |
String |
getVirtualHost() |
boolean |
removeConnectionListener(ConnectionListener listener) |
void |
setDefaultTargetConnectionFactory(ConnectionFactory defaultTargetConnectionFactory)
Specify the default target
ConnectionFactory, if any. |
void |
setLenientFallback(boolean lenientFallback)
Specify whether to apply a lenient fallback to the default
ConnectionFactory
if no specific ConnectionFactory could be found for the current lookup key. |
void |
setTargetConnectionFactories(Map<Object,ConnectionFactory> targetConnectionFactories)
Specify the map of target ConnectionFactories, with the lookup key as key.
|
public void setTargetConnectionFactories(Map<Object,ConnectionFactory> targetConnectionFactories)
The key can be of arbitrary type; this class implements the
generic lookup process only. The concrete key representation will
be handled by determineCurrentLookupKey().
targetConnectionFactories - The target connection factories and lookup keys.public void setDefaultTargetConnectionFactory(ConnectionFactory defaultTargetConnectionFactory)
ConnectionFactory, if any.
This ConnectionFactory will be used as target if none of the keyed
targetConnectionFactories match the
determineCurrentLookupKey() current lookup key.
defaultTargetConnectionFactory - The default target connection factory.public void setLenientFallback(boolean lenientFallback)
ConnectionFactory
if no specific ConnectionFactory could 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 default
ConnectionFactory in 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 a ConnectionFactory
entry will then lead to an IllegalStateException.
lenientFallback - true to fall back to the default, if specified.setTargetConnectionFactories(java.util.Map<java.lang.Object, org.springframework.amqp.rabbit.connection.ConnectionFactory>),
setDefaultTargetConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory),
determineCurrentLookupKey()public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic Connection createConnection() throws AmqpException
createConnection in interface ConnectionFactoryAmqpExceptionprotected ConnectionFactory determineTargetConnectionFactory()
ConnectionFactory. Determines the
current lookup key, performs
a lookup in the targetConnectionFactories map,
falls back to the specified
defaultTargetConnectionFactory if necessary.determineCurrentLookupKey()public void addConnectionListener(ConnectionListener listener)
addConnectionListener in interface ConnectionFactorypublic boolean removeConnectionListener(ConnectionListener listener)
removeConnectionListener in interface ConnectionFactorypublic void clearConnectionListeners()
clearConnectionListeners in interface ConnectionFactorypublic String getHost()
getHost in interface ConnectionFactorypublic int getPort()
getPort in interface ConnectionFactorypublic String getVirtualHost()
getVirtualHost in interface ConnectionFactoryprotected abstract Object determineCurrentLookupKey()