Class AbstractConnectionFactory

java.lang.Object
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
All Implemented Interfaces:
com.rabbitmq.client.ShutdownListener, EventListener, ConnectionFactory, Aware, BeanNameAware, DisposableBean, ApplicationContextAware, ApplicationEventPublisherAware, ApplicationListener<ContextClosedEvent>
Direct Known Subclasses:
CachingConnectionFactory, PooledChannelConnectionFactory, ThreadChannelConnectionFactory

public abstract class AbstractConnectionFactory extends Object implements ConnectionFactory, DisposableBean, BeanNameAware, ApplicationContextAware, ApplicationEventPublisherAware, ApplicationListener<ContextClosedEvent>, com.rabbitmq.client.ShutdownListener
Author:
Dave Syer, Gary Russell, Steve Powell, Artem Bilan, Will Droste, Christian Tzolov, Salk Lee
  • Field Details Link icon

    • DEFAULT_CLOSE_TIMEOUT Link icon

      public static final int DEFAULT_CLOSE_TIMEOUT
      See Also:
    • logger Link icon

      protected final Log logger
  • Constructor Details Link icon

    • AbstractConnectionFactory Link icon

      public AbstractConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
      Create a new AbstractConnectionFactory for the given target ConnectionFactory, with no publisher connection factory.
      Parameters:
      rabbitConnectionFactory - the target ConnectionFactory
  • Method Details Link icon

    • setPublisherConnectionFactory Link icon

      public void setPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory)
      Set a custom publisher connection factory; the type does not need to be the same as this factory.
      Parameters:
      publisherConnectionFactory - the factory.
      Since:
      2.3.2
    • doSetPublisherConnectionFactory Link icon

      protected final void doSetPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory)
    • setApplicationContext Link icon

      public void setApplicationContext(ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface ApplicationContextAware
    • getApplicationContext Link icon

      protected ApplicationContext getApplicationContext()
    • setApplicationEventPublisher Link icon

      public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
      Specified by:
      setApplicationEventPublisher in interface ApplicationEventPublisherAware
    • getApplicationEventPublisher Link icon

      protected @Nullable ApplicationEventPublisher getApplicationEventPublisher()
    • onApplicationEvent Link icon

      public void onApplicationEvent(ContextClosedEvent event)
      Specified by:
      onApplicationEvent in interface ApplicationListener<ContextClosedEvent>
    • getContextStopped Link icon

      protected boolean getContextStopped()
    • getRabbitConnectionFactory Link icon

      public com.rabbitmq.client.ConnectionFactory getRabbitConnectionFactory()
      Return a reference to the underlying Rabbit Connection factory.
      Returns:
      the connection factory.
      Since:
      1.5.6
    • getUsername Link icon

      public String getUsername()
      Return the username from the underlying rabbit connection factory.
      Specified by:
      getUsername in interface ConnectionFactory
      Returns:
      the username.
      Since:
      1.6
    • setUsername Link icon

      public void setUsername(String username)
    • setPassword Link icon

      public void setPassword(String password)
    • setHost Link icon

      public void setHost(String host)
    • setConnectionThreadFactory Link icon

      public void setConnectionThreadFactory(ThreadFactory threadFactory)
      Set the ThreadFactory on the underlying rabbit connection factory.
      Parameters:
      threadFactory - the thread factory.
      Since:
      1.5.3
    • setAddressResolver Link icon

      public void setAddressResolver(com.rabbitmq.client.AddressResolver addressResolver)
      Set an AddressResolver to use when creating connections; overrides setAddresses(String), setHost(String), and setPort(int).
      Parameters:
      addressResolver - the resolver.
      Since:
      2.1.15
    • setUri Link icon

      public void setUri(URI uri)
      Parameters:
      uri - the URI
      Since:
      1.5
      See Also:
      • ConnectionFactory.setUri(URI)
    • setUri Link icon

      public void setUri(String uri)
      Parameters:
      uri - the URI
      Since:
      1.5
      See Also:
      • ConnectionFactory.setUri(String)
    • getHost Link icon

      public @Nullable String getHost()
      Specified by:
      getHost in interface ConnectionFactory
    • setVirtualHost Link icon

      public void setVirtualHost(String virtualHost)
    • getVirtualHost Link icon

      public String getVirtualHost()
      Specified by:
      getVirtualHost in interface ConnectionFactory
    • setPort Link icon

      public void setPort(int port)
    • setRequestedHeartBeat Link icon

      public void setRequestedHeartBeat(int requestedHeartBeat)
    • setConnectionTimeout Link icon

      public void setConnectionTimeout(int connectionTimeout)
    • getPort Link icon

      public int getPort()
      Specified by:
      getPort in interface ConnectionFactory
    • setAddresses Link icon

      public void setAddresses(List<String> addresses)
      Set addresses for clustering. This property overrides the host+port properties if not empty.
      Parameters:
      addresses - list of addresses in form host[:port].
      Since:
      3.2.1
    • setAddresses Link icon

      public void setAddresses(String addresses)
      Set addresses for clustering. This property overrides the host+port properties if not empty.
      Parameters:
      addresses - list of addresses with form host1[:port1],host2[:port2],....
    • getAddresses Link icon

      protected @Nullable List<com.rabbitmq.client.Address> getAddresses() throws IOException
      Throws:
      IOException
    • getConnectionListener Link icon

      protected ConnectionListener getConnectionListener()
      A composite connection listener to be used by subclasses when creating and closing connections.
      Returns:
      the connection listener
    • getChannelListener Link icon

      protected ChannelListener getChannelListener()
      A composite channel listener to be used by subclasses when creating and closing channels.
      Returns:
      the channel listener
    • setConnectionListeners Link icon

      public void setConnectionListeners(List<? extends ConnectionListener> listeners)
    • addConnectionListener Link icon

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

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

      public void clearConnectionListeners()
      Specified by:
      clearConnectionListeners in interface ConnectionFactory
    • setChannelListeners Link icon

      public void setChannelListeners(List<? extends ChannelListener> listeners)
    • setRecoveryListener Link icon

      public void setRecoveryListener(com.rabbitmq.client.RecoveryListener recoveryListener)
      Set a RecoveryListener that will be added to each connection created.
      Parameters:
      recoveryListener - the listener.
      Since:
      2.0
    • addChannelListener Link icon

      public void addChannelListener(ChannelListener listener)
    • setExecutor Link icon

      public void setExecutor(Executor executor)
      Provide an Executor for use by the Rabbit ConnectionFactory when creating connections. Can either be an ExecutorService or a Spring ThreadPoolTaskExecutor, as defined by a <task:executor/> element.
      Parameters:
      executor - The executor.
    • getExecutorService Link icon

      protected @Nullable ExecutorService getExecutorService()
    • setCloseTimeout Link icon

      public void setCloseTimeout(int closeTimeout)
      How long to wait (milliseconds) for a response to a connection close operation from the broker; default 30000 (30 seconds). Also used for Channel.waitForConfirms().
      Parameters:
      closeTimeout - the closeTimeout to set.
    • getCloseTimeout Link icon

      public int getCloseTimeout()
    • setConnectionNameStrategy Link icon

      public void setConnectionNameStrategy(ConnectionNameStrategy connectionNameStrategy)
      Provide a ConnectionNameStrategy to build the name for the target RabbitMQ connection. The beanName together with a counter is used by default.
      Parameters:
      connectionNameStrategy - the ConnectionNameStrategy to use.
      Since:
      2.0
    • setCloseExceptionLogger Link icon

      public void setCloseExceptionLogger(ConditionalExceptionLogger closeExceptionLogger)
      Set the strategy for logging close exceptions; by default, if a channel is closed due to a failed passive queue declaration, it is logged at debug level. Normal channel closes (200 OK) are not logged. All others are logged at ERROR level (unless access is refused due to an exclusive consumer condition, in which case, it is logged at DEBUG level, since 3.1, previously INFO).
      Parameters:
      closeExceptionLogger - the ConditionalExceptionLogger.
      Since:
      1.5
    • getConnectionNameStrategy Link icon

      protected ConnectionNameStrategy getConnectionNameStrategy()
    • setBeanName Link icon

      public void setBeanName(String name)
      Specified by:
      setBeanName in interface BeanNameAware
    • getBeanName Link icon

      protected @Nullable String getBeanName()
      Return a bean name of the component or null if not a bean.
      Returns:
      the bean name or null.
      Since:
      1.7.9
    • setAddressShuffleMode Link icon

      public void setAddressShuffleMode(AbstractConnectionFactory.AddressShuffleMode addressShuffleMode)
      Set the mode for shuffling addresses.
      Parameters:
      addressShuffleMode - the address shuffle mode.
      Since:
      2.3
      See Also:
    • hasPublisherConnectionFactory Link icon

      public boolean hasPublisherConnectionFactory()
    • setConnectionCreatingBackOff Link icon

      public void setConnectionCreatingBackOff(@Nullable BackOff backOff)
      Set the backoff strategy for creating connections. This enhancement supports custom retry policies within the connection module, particularly useful when the maximum channel limit is reached. The SimpleConnection.createChannel(boolean) method utilizes this backoff strategy to gracefully handle such limit exceptions.
      Parameters:
      backOff - the backoff strategy to be applied during connection creation
      Since:
      3.1.3
    • getPublisherConnectionFactory Link icon

      public @Nullable ConnectionFactory getPublisherConnectionFactory()
      Description copied from interface: ConnectionFactory
      Return a separate connection factory for publishers (if implemented).
      Specified by:
      getPublisherConnectionFactory in interface ConnectionFactory
      Returns:
      the publisher connection factory, or null.
    • createBareConnection Link icon

      protected final Connection createBareConnection()
    • getDefaultHostName Link icon

      protected final String getDefaultHostName()
    • shutdownCompleted Link icon

      public void shutdownCompleted(com.rabbitmq.client.ShutdownSignalException cause)
      Specified by:
      shutdownCompleted in interface com.rabbitmq.client.ShutdownListener
    • destroy Link icon

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object