Class PooledChannelConnectionFactory

java.lang.Object
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
org.springframework.amqp.rabbit.connection.PooledChannelConnectionFactory
All Implemented Interfaces:
com.rabbitmq.client.ShutdownListener, EventListener, ConnectionFactory, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextClosedEvent>, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle

public class PooledChannelConnectionFactory extends AbstractConnectionFactory implements com.rabbitmq.client.ShutdownListener, org.springframework.context.SmartLifecycle
A very simple connection factory that caches channels using Apache Pool2 GenericObjectPools (one for transactional and one for non-transactional channels). The pools have default configuration but they can be configured using a callback.
Since:
2.3
  • Constructor Details

    • PooledChannelConnectionFactory

      public PooledChannelConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
      Construct an instance.
      Parameters:
      rabbitConnectionFactory - the rabbitmq connection factory.
  • Method Details

    • setPublisherConnectionFactory

      public void setPublisherConnectionFactory(@Nullable AbstractConnectionFactory publisherConnectionFactory)
      Description copied from class: AbstractConnectionFactory
      Set a custom publisher connection factory; the type does not need to be the same as this factory.
      Overrides:
      setPublisherConnectionFactory in class AbstractConnectionFactory
      Parameters:
      publisherConnectionFactory - the factory.
    • setPoolConfigurer

      public void setPoolConfigurer(BiConsumer<org.apache.commons.pool2.impl.GenericObjectPool<com.rabbitmq.client.Channel>,Boolean> poolConfigurer)
      Add a consumer to configure the object pool. The second argument is true when called with the transactional pool.
      Parameters:
      poolConfigurer - the configurer.
    • isSimplePublisherConfirms

      public boolean isSimplePublisherConfirms()
      Description copied from interface: ConnectionFactory
      Return true if simple publisher confirms are enabled.
      Specified by:
      isSimplePublisherConfirms in interface ConnectionFactory
      Returns:
      simplePublisherConfirms
    • setSimplePublisherConfirms

      public void setSimplePublisherConfirms(boolean simplePublisherConfirms)
      Enable simple publisher confirms.
      Parameters:
      simplePublisherConfirms - true to enable.
    • addConnectionListener

      public void addConnectionListener(ConnectionListener listener)
      Specified by:
      addConnectionListener in interface ConnectionFactory
      Overrides:
      addConnectionListener in class AbstractConnectionFactory
    • 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
    • createConnection

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

      public void resetConnection()
      Close the connection(s). This will impact any in-process operations. New connection(s) will be created on demand after this method returns. This might be used to force a reconnect to the primary broker after failing over to a secondary broker.
      Specified by:
      resetConnection in interface ConnectionFactory
    • destroy

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