Class ThreadChannelConnectionFactory

java.lang.Object
org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
org.springframework.amqp.rabbit.connection.ThreadChannelConnectionFactory
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 ThreadChannelConnectionFactory extends AbstractConnectionFactory implements com.rabbitmq.client.ShutdownListener, org.springframework.context.SmartLifecycle
A very simple connection factory that caches a channel per thread. Users are responsible for releasing the thread's channel by calling closeThreadChannel().
Since:
2.3
  • Constructor Details

    • ThreadChannelConnectionFactory

      public ThreadChannelConnectionFactory(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.
    • 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.
    • 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
      Overrides:
      addConnectionListener in class AbstractConnectionFactory
    • createConnection

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

      public void closeThreadChannel()
      Close the channel associated with this thread, if any.
    • 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
    • prepareSwitchContext

      @Nullable public Object prepareSwitchContext()
      Call to prepare to switch the channel(s) owned by this thread to another thread.
      Returns:
      an opaque object representing the context to switch. If there are no channels or no open channels assigned to this thread, null is returned.
      Since:
      2.3.7
      See Also:
    • switchContext

      public void switchContext(@Nullable Object toSwitch)
      Acquire ownership of another thread's channel(s) after that thread called prepareSwitchContext().
      Parameters:
      toSwitch - the context returned by prepareSwitchContext().
      Since:
      2.3.7
      See Also: