Class DefaultChannelPool

  • All Implemented Interfaces:
    io.micronaut.core.naming.Named, ChannelPool, java.lang.AutoCloseable

    @EachBean(com.rabbitmq.client.Connection.class)
    public class DefaultChannelPool
    extends java.lang.Object
    implements java.lang.AutoCloseable, ChannelPool
    Default implementation of ChannelPool. There is no limit to the number of channels that can be created. If the channel list is empty a new channel will be created and returned. The maximum number of channels should be the maximum number of concurrent operations.
    Since:
    1.1.0
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      protected com.rabbitmq.client.Channel createChannel()
      Creates a channel.
      com.rabbitmq.client.Channel getChannel()
      Retrieves a channel from the pool.
      com.rabbitmq.client.Channel getChannelWithRecoveringDelay​(int recoveryAttempts)
      Retrieves a channel from the pool after blocking the thread for a delay period defined by the RecoveryDelayHandler of the connection for this pool.
      java.lang.String getName()  
      boolean isTopologyRecoveryEnabled()
      Returns whether topology recovery is enabled for the connection of this pool.
      void returnChannel​(com.rabbitmq.client.Channel channel)
      Returns a channel to the pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultChannelPool

        public DefaultChannelPool​(@Parameter
                                  java.lang.String name,
                                  @Parameter
                                  com.rabbitmq.client.Connection connection,
                                  @Parameter
                                  RabbitConnectionFactoryConfig config)
        Default constructor.
        Parameters:
        name - The pool name
        connection - The connection
        config - The connection factory config
    • Method Detail

      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface io.micronaut.core.naming.Named
      • getChannel

        public com.rabbitmq.client.Channel getChannel()
                                               throws java.io.IOException
        Description copied from interface: ChannelPool
        Retrieves a channel from the pool. The channel must be returned to the pool after it is no longer being used.
        Specified by:
        getChannel in interface ChannelPool
        Returns:
        The channel
        Throws:
        java.io.IOException - If a channel needed to be created and encountered an error
      • getChannelWithRecoveringDelay

        public com.rabbitmq.client.Channel getChannelWithRecoveringDelay​(int recoveryAttempts)
                                                                  throws java.io.IOException,
                                                                         java.lang.InterruptedException
        Description copied from interface: ChannelPool
        Retrieves a channel from the pool after blocking the thread for a delay period defined by the RecoveryDelayHandler of the connection for this pool.
        Specified by:
        getChannelWithRecoveringDelay in interface ChannelPool
        Parameters:
        recoveryAttempts - the number of recovery attempts so far
        Returns:
        a channel from the pool
        Throws:
        java.io.IOException - if a channel needed to be created and encountered an error
        java.lang.InterruptedException - if the thread was interrupted during the delay period
      • isTopologyRecoveryEnabled

        public boolean isTopologyRecoveryEnabled()
        Description copied from interface: ChannelPool
        Returns whether topology recovery is enabled for the connection of this pool.
        Specified by:
        isTopologyRecoveryEnabled in interface ChannelPool
        Returns:
        true by default
      • returnChannel

        public void returnChannel​(com.rabbitmq.client.Channel channel)
        Description copied from interface: ChannelPool
        Returns a channel to the pool. No further use of the channel is allowed by the returner.
        Specified by:
        returnChannel in interface ChannelPool
        Parameters:
        channel - The channel
      • createChannel

        protected com.rabbitmq.client.Channel createChannel()
                                                     throws java.io.IOException
        Creates a channel.
        Returns:
        The newly created channel
        Throws:
        java.io.IOException - If an error occurred creating the channel
      • close

        @PreDestroy
        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable