Class ThreadChannelConnectionFactory

  • All Implemented Interfaces:
    com.rabbitmq.client.ShutdownListener, java.util.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>

    public class ThreadChannelConnectionFactory
    extends AbstractConnectionFactory
    implements com.rabbitmq.client.ShutdownListener
    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 Detail

      • ThreadChannelConnectionFactory

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

      • setSimplePublisherConfirms

        public void setSimplePublisherConfirms​(boolean simplePublisherConfirms)
        Enable simple publisher confirms.
        Parameters:
        simplePublisherConfirms - true to enable.
      • 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.
      • destroy

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

        @Nullable
        public java.lang.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(Object)