Class LocalizedQueueConnectionFactory
- java.lang.Object
-
- org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory
-
- All Implemented Interfaces:
ConnectionFactory,RoutingConnectionFactory,DisposableBean
public class LocalizedQueueConnectionFactory extends java.lang.Object implements ConnectionFactory, RoutingConnectionFactory, DisposableBean
ARoutingConnectionFactorythat determines the node on which a queue is located and returns a factory that connects directly to that node. The RabbitMQ management plugin is called over REST to determine the node and the corresponding address for that node is injected into the connection factory. A single instance of each connection factory is retained in a cache. If the location cannot be determined, the default connection factory is returned. This connection factory is typically configured to connect to all the servers in a fail-over mode.getTargetConnectionFactory(Object)is invoked by theSimpleMessageListenerContainer, when establishing a connection, with the lookup key having the format'[queueName]'.All
ConnectionFactorymethods delegate to the default- Since:
- 1.2
- Author:
- Gary Russell
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLocalizedQueueConnectionFactory.FactoryFinderCallback to determine the connection factory using the provided information.static interfaceLocalizedQueueConnectionFactory.NodeLocator<T>Used to obtain a connection factory for the queue leader.
-
Constructor Summary
Constructors Constructor Description LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.lang.String[] addresses, java.lang.String[] adminUris, java.lang.String[] nodes, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, java.lang.String keyStore, java.lang.String trustStore, java.lang.String keyStorePassPhrase, java.lang.String trustStorePassPhrase)LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.lang.String[] addresses, java.lang.String[] adminUris, java.lang.String[] nodes, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, Resource sslPropertiesLocation)LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.util.Map<java.lang.String,java.lang.String> nodeToAddress, java.lang.String[] adminUris, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, java.lang.String keyStore, java.lang.String trustStore, java.lang.String keyStorePassPhrase, java.lang.String trustStorePassPhrase)LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.util.Map<java.lang.String,java.lang.String> nodeToAddress, java.lang.String[] adminUris, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, Resource sslPropertiesLocation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConnectionListener(ConnectionListener listener)voidclearConnectionListeners()ConnectioncreateConnection()protected ConnectionFactorycreateConnectionFactory(java.lang.String address, java.lang.String node)Create a dedicated connection factory for the address.voiddestroy()java.lang.StringgetHost()intgetPort()ConnectionFactorygetTargetConnectionFactory(java.lang.Object key)Returns theConnectionFactorybound to given lookup key, or null if one does not exist.java.lang.StringgetUsername()java.lang.StringgetVirtualHost()booleanremoveConnectionListener(ConnectionListener listener)voidresetConnection()Close any connection(s) that might be cached by this factory.voidsetNodeLocator(LocalizedQueueConnectionFactory.NodeLocator<?> nodeLocator)Set aLocalizedQueueConnectionFactory.NodeLocatorto use to find the node address for the leader.-
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, isPublisherConfirms, isPublisherReturns, isSimplePublisherConfirms
-
-
-
-
Constructor Detail
-
LocalizedQueueConnectionFactory
public LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.util.Map<java.lang.String,java.lang.String> nodeToAddress, java.lang.String[] adminUris, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, Resource sslPropertiesLocation)
- Parameters:
defaultConnectionFactory- the fallback connection factory to use if the queue can't be located.nodeToAddress- a Map of node to address: (rabbit@server1 : server1:5672)adminUris- the rabbitmq admin addresses (https://host:port, ...) must be the same length as addresses.vhost- the virtual host.username- the user name.password- the password.useSSL- use SSL.sslPropertiesLocation- the SSL properties location.
-
LocalizedQueueConnectionFactory
public LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.util.Map<java.lang.String,java.lang.String> nodeToAddress, java.lang.String[] adminUris, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, java.lang.String keyStore, java.lang.String trustStore, java.lang.String keyStorePassPhrase, java.lang.String trustStorePassPhrase)
- Parameters:
defaultConnectionFactory- the fallback connection factory to use if the queue can't be located.nodeToAddress- a Map of node to address: (rabbit@server1 : server1:5672)adminUris- the rabbitmq admin addresses (https://host:port, ...) must be the same length as addresses.vhost- the virtual host.username- the user name.password- the password.useSSL- use SSL.keyStore- the key store resource (e.g. "file:/foo/keystore").trustStore- the trust store resource (e.g. "file:/foo/truststore").keyStorePassPhrase- the pass phrase for the key store.trustStorePassPhrase- the pass phrase for the trust store.
-
LocalizedQueueConnectionFactory
public LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.lang.String[] addresses, java.lang.String[] adminUris, java.lang.String[] nodes, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, @Nullable Resource sslPropertiesLocation)
- Parameters:
defaultConnectionFactory- the fallback connection factory to use if the queue can't be located.addresses- the rabbitmq server addresses (host:port, ...).adminUris- the rabbitmq admin addresses (https://host:port, ...)nodes- the rabbitmq nodes corresponding to addresses (rabbit@server1, ...) must be the same length as addresses.vhost- the virtual host.username- the user name.password- the password.useSSL- use SSL.sslPropertiesLocation- the SSL properties location.
-
LocalizedQueueConnectionFactory
public LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, java.lang.String[] addresses, java.lang.String[] adminUris, java.lang.String[] nodes, java.lang.String vhost, java.lang.String username, java.lang.String password, boolean useSSL, java.lang.String keyStore, java.lang.String trustStore, java.lang.String keyStorePassPhrase, java.lang.String trustStorePassPhrase)
- Parameters:
defaultConnectionFactory- the fallback connection factory to use if the queue can't be located.addresses- the rabbitmq server addresses (host:port, ...).adminUris- the rabbitmq admin addresses (https://host:port, ...).nodes- the rabbitmq nodes corresponding to addresses (rabbit@server1, ...) must be the same length as addresses.vhost- the virtual host.username- the user name.password- the password.useSSL- use SSL.keyStore- the key store resource (e.g. "file:/foo/keystore").trustStore- the trust store resource (e.g. "file:/foo/truststore").keyStorePassPhrase- the pass phrase for the key store.trustStorePassPhrase- the pass phrase for the trust store.
-
-
Method Detail
-
setNodeLocator
public void setNodeLocator(LocalizedQueueConnectionFactory.NodeLocator<?> nodeLocator)
Set aLocalizedQueueConnectionFactory.NodeLocatorto use to find the node address for the leader.- Parameters:
nodeLocator- the locator.- Since:
- 2.4.8
-
createConnection
public Connection createConnection() throws AmqpException
- Specified by:
createConnectionin interfaceConnectionFactory- Throws:
AmqpException
-
getHost
public java.lang.String getHost()
- Specified by:
getHostin interfaceConnectionFactory
-
getPort
public int getPort()
- Specified by:
getPortin interfaceConnectionFactory
-
getVirtualHost
public java.lang.String getVirtualHost()
- Specified by:
getVirtualHostin interfaceConnectionFactory
-
getUsername
public java.lang.String getUsername()
- Specified by:
getUsernamein interfaceConnectionFactory
-
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
-
getTargetConnectionFactory
public ConnectionFactory getTargetConnectionFactory(java.lang.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
-
createConnectionFactory
protected ConnectionFactory createConnectionFactory(java.lang.String address, java.lang.String node)
Create a dedicated connection factory for the address.- Parameters:
address- the address to which the factory should connect.node- the node.- Returns:
- the connection factory.
-
resetConnection
public void resetConnection()
Description copied from interface:ConnectionFactoryClose any connection(s) that might be cached by this factory. This does not prevent new connections from being opened.- Specified by:
resetConnectionin interfaceConnectionFactory
-
destroy
public void destroy()
- Specified by:
destroyin interfaceDisposableBean
-
-