public class LocalizedQueueConnectionFactory
extends java.lang.Object
implements org.springframework.amqp.rabbit.connection.ConnectionFactory, org.springframework.amqp.rabbit.connection.RoutingConnectionFactory
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(org.springframework.amqp.rabbit.connection.ConnectionFactory defaultConnectionFactory,
java.lang.String[] addresses,
java.lang.String[] adminAddresses,
java.lang.String[] nodes,
java.lang.String vhost,
java.lang.String username,
java.lang.String password,
boolean useSSL,
org.springframework.core.io.Resource sslPropertiesLocation) |
Modifier and Type | Method and Description |
---|---|
void |
addConnectionListener(org.springframework.amqp.rabbit.connection.ConnectionListener listener) |
void |
clearConnectionListeners() |
org.springframework.amqp.rabbit.connection.Connection |
createConnection() |
protected org.springframework.amqp.rabbit.connection.ConnectionFactory |
createConnectionFactory(java.lang.String address)
Create a dedicated connection factory for the address.
|
protected org.springframework.web.client.RestTemplate |
createRestTemplate(java.lang.String adminUri)
Create a RestTemplate for the supplied URI.
|
java.lang.String |
getHost() |
int |
getPort() |
org.springframework.amqp.rabbit.connection.ConnectionFactory |
getTargetConnectionFactory(java.lang.Object key) |
java.lang.String |
getVirtualHost() |
boolean |
removeConnectionListener(org.springframework.amqp.rabbit.connection.ConnectionListener listener) |
public LocalizedQueueConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory defaultConnectionFactory, java.lang.String[] addresses, java.lang.String[] adminAddresses, 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, ...).adminAddresses
- the rabbitmq admin addresses (http://host:port, ...) must be the same length
as addresses.nodes
- the rabbitmq nodes corresponding to addresses (rabbit@server1, ...).vhost
- the virtual host.username
- the user name.password
- the password.public org.springframework.amqp.rabbit.connection.Connection createConnection() throws org.springframework.amqp.AmqpException
createConnection
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
org.springframework.amqp.AmqpException
public java.lang.String getHost()
getHost
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public int getPort()
getPort
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public java.lang.String getVirtualHost()
getVirtualHost
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public void addConnectionListener(org.springframework.amqp.rabbit.connection.ConnectionListener listener)
addConnectionListener
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public boolean removeConnectionListener(org.springframework.amqp.rabbit.connection.ConnectionListener listener)
removeConnectionListener
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public void clearConnectionListeners()
clearConnectionListeners
in interface org.springframework.amqp.rabbit.connection.ConnectionFactory
public org.springframework.amqp.rabbit.connection.ConnectionFactory getTargetConnectionFactory(java.lang.Object key)
getTargetConnectionFactory
in interface org.springframework.amqp.rabbit.connection.RoutingConnectionFactory
protected org.springframework.web.client.RestTemplate createRestTemplate(java.lang.String adminUri)
adminUri
- the URI.protected org.springframework.amqp.rabbit.connection.ConnectionFactory createConnectionFactory(java.lang.String address) throws java.lang.Exception
address
- the address to which the factory should connect.java.lang.Exception
- if errors occur during creation.