Class DefaultChannelPool

java.lang.Object
io.micronaut.rabbitmq.connect.DefaultChannelPool
All Implemented Interfaces:
io.micronaut.core.naming.Named, ChannelPool, AutoCloseable

@EachBean(com.rabbitmq.client.Connection.class) public class DefaultChannelPool extends Object implements 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
Author:
James Kleeh
  • Constructor Details

    • DefaultChannelPool

      public DefaultChannelPool(@Parameter 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 Details

    • getName

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

      public com.rabbitmq.client.Channel getChannel() throws 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:
      IOException - If a channel needed to be created and encountered an error
    • getChannelWithRecoveringDelay

      public com.rabbitmq.client.Channel getChannelWithRecoveringDelay(int recoveryAttempts) throws IOException, 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:
      IOException - if a channel needed to be created and encountered an error
      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 IOException
      Creates a channel.
      Returns:
      The newly created channel
      Throws:
      IOException - If an error occurred creating the channel
    • close

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