public class LocalizedQueueConnectionFactory extends java.lang.Object implements ConnectionFactory, RoutingConnectionFactory, org.springframework.beans.factory.DisposableBean
RoutingConnectionFactory
that 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 the
SimpleMessageListenerContainer
, when establishing a connection, with the lookup key having
the format '[queueName]'
.
All ConnectionFactory
methods delegate to the default
Constructor and Description |
---|
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,
org.springframework.core.io.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.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,
org.springframework.core.io.Resource sslPropertiesLocation) |
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) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(ConnectionListener listener) |
void |
clearConnectionListeners() |
protected com.rabbitmq.http.client.Client |
createClient(java.lang.String adminUri,
java.lang.String username,
java.lang.String password)
Create a client instance.
|
Connection |
createConnection() |
protected ConnectionFactory |
createConnectionFactory(java.lang.String address,
java.lang.String node)
Create a dedicated connection factory for the address.
|
void |
destroy() |
java.lang.String |
getHost() |
int |
getPort() |
ConnectionFactory |
getTargetConnectionFactory(java.lang.Object key)
Returns the
ConnectionFactory bound to given lookup key, or null if one does not exist. |
java.lang.String |
getUsername() |
java.lang.String |
getVirtualHost() |
boolean |
removeConnectionListener(ConnectionListener listener) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPublisherConnectionFactory
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, org.springframework.core.io.Resource sslPropertiesLocation)
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 (http://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.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)
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 (http://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.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, org.springframework.core.io.Resource sslPropertiesLocation)
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 (http://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.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)
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 (http://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.public Connection createConnection() throws AmqpException
createConnection
in interface ConnectionFactory
AmqpException
public java.lang.String getHost()
getHost
in interface ConnectionFactory
public int getPort()
getPort
in interface ConnectionFactory
public java.lang.String getVirtualHost()
getVirtualHost
in interface ConnectionFactory
public java.lang.String getUsername()
getUsername
in interface ConnectionFactory
public void addConnectionListener(ConnectionListener listener)
addConnectionListener
in interface ConnectionFactory
public boolean removeConnectionListener(ConnectionListener listener)
removeConnectionListener
in interface ConnectionFactory
public void clearConnectionListeners()
clearConnectionListeners
in interface ConnectionFactory
public ConnectionFactory getTargetConnectionFactory(java.lang.Object key)
RoutingConnectionFactory
ConnectionFactory
bound to given lookup key, or null if one does not exist.getTargetConnectionFactory
in interface RoutingConnectionFactory
key
- The lookup key to which the ConnectionFactory
is boundConnectionFactory
bound to the given lookup key, or null if one does not existprotected com.rabbitmq.http.client.Client createClient(java.lang.String adminUri, java.lang.String username, java.lang.String password) throws java.net.MalformedURLException, java.net.URISyntaxException
adminUri
- the admin URI.username
- the usernamepassword
- the password.java.net.MalformedURLException
- if the URL is malformedjava.net.URISyntaxException
- if there is a syntax error.protected ConnectionFactory createConnectionFactory(java.lang.String address, java.lang.String node) throws java.lang.Exception
address
- the address to which the factory should connect.node
- the node.java.lang.Exception
- if errors occur during creation.public void destroy() throws java.lang.Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
java.lang.Exception