Class LocalizedQueueConnectionFactory

java.lang.Object
org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory
All Implemented Interfaces:
ConnectionFactory, RoutingConnectionFactory, org.springframework.beans.factory.DisposableBean, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class LocalizedQueueConnectionFactory extends Object implements ConnectionFactory, RoutingConnectionFactory, org.springframework.beans.factory.DisposableBean, org.springframework.context.SmartLifecycle
A 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

Since:
1.2
  • Constructor Details

    • LocalizedQueueConnectionFactory

      public LocalizedQueueConnectionFactory(ConnectionFactory defaultConnectionFactory, Map<String,String> nodeToAddress, String[] adminUris, String vhost, String username, String password, boolean useSSL, org.springframework.core.io.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, Map<String,String> nodeToAddress, String[] adminUris, String vhost, String username, String password, boolean useSSL, String keyStore, String trustStore, String keyStorePassPhrase, 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, String[] addresses, String[] adminUris, String[] nodes, String vhost, String username, String password, boolean useSSL, @Nullable org.springframework.core.io.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, String[] addresses, String[] adminUris, String[] nodes, String vhost, String username, String password, boolean useSSL, String keyStore, String trustStore, String keyStorePassPhrase, 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 Details

    • setNodeLocator

      public void setNodeLocator(NodeLocator<?> nodeLocator)
      Set a NodeLocator to use to find the node address for the leader.
      Parameters:
      nodeLocator - the locator.
      Since:
      2.4.8
    • createConnection

      public Connection createConnection() throws org.springframework.amqp.AmqpException
      Specified by:
      createConnection in interface ConnectionFactory
      Throws:
      org.springframework.amqp.AmqpException
    • getHost

      public String getHost()
      Specified by:
      getHost in interface ConnectionFactory
    • getPort

      public int getPort()
      Specified by:
      getPort in interface ConnectionFactory
    • getVirtualHost

      public String getVirtualHost()
      Specified by:
      getVirtualHost in interface ConnectionFactory
    • getUsername

      public String getUsername()
      Specified by:
      getUsername in interface ConnectionFactory
    • getPhase

      public int getPhase()
      Specified by:
      getPhase in interface org.springframework.context.Phased
      Specified by:
      getPhase in interface org.springframework.context.SmartLifecycle
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • addConnectionListener

      public void addConnectionListener(ConnectionListener listener)
      Specified by:
      addConnectionListener in interface ConnectionFactory
    • removeConnectionListener

      public boolean removeConnectionListener(ConnectionListener listener)
      Specified by:
      removeConnectionListener in interface ConnectionFactory
    • clearConnectionListeners

      public void clearConnectionListeners()
      Specified by:
      clearConnectionListeners in interface ConnectionFactory
    • getTargetConnectionFactory

      public ConnectionFactory getTargetConnectionFactory(Object key)
      Description copied from interface: RoutingConnectionFactory
      Returns the ConnectionFactory bound to given lookup key, or null if one does not exist.
      Specified by:
      getTargetConnectionFactory in interface RoutingConnectionFactory
      Parameters:
      key - The lookup key to which the ConnectionFactory is bound
      Returns:
      the ConnectionFactory bound to the given lookup key, or null if one does not exist
    • createConnectionFactory

      protected ConnectionFactory createConnectionFactory(String address, 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: ConnectionFactory
      Close any connection(s) that might be cached by this factory. This does not prevent new connections from being opened.
      Specified by:
      resetConnection in interface ConnectionFactory
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean