Package io.micronaut.rabbitmq.connect
Class DefaultChannelPool
- java.lang.Object
-
- io.micronaut.rabbitmq.connect.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 ofChannelPool. 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
-
-
Field Summary
-
Fields inherited from interface io.micronaut.rabbitmq.connect.ChannelPool
DEFAULT_RECOVERY_DELAY
-
-
Constructor Summary
Constructors Constructor Description DefaultChannelPool(java.lang.String name, com.rabbitmq.client.Connection connection, RabbitConnectionFactoryConfig config)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected com.rabbitmq.client.ChannelcreateChannel()Creates a channel.com.rabbitmq.client.ChannelgetChannel()Retrieves a channel from the pool.com.rabbitmq.client.ChannelgetChannelWithRecoveringDelay(int recoveryAttempts)Retrieves a channel from the pool after blocking the thread for a delay period defined by theRecoveryDelayHandlerof the connection for this pool.java.lang.StringgetName()booleanisTopologyRecoveryEnabled()Returns whethertopology recoveryis enabled for the connection of this pool.voidreturnChannel(com.rabbitmq.client.Channel channel)Returns a channel to the pool.
-
-
-
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 nameconnection- The connectionconfig- The connection factory config
-
-
Method Detail
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceio.micronaut.core.naming.Named
-
getChannel
public com.rabbitmq.client.Channel getChannel() throws java.io.IOExceptionDescription copied from interface:ChannelPoolRetrieves a channel from the pool. The channel must be returned to the pool after it is no longer being used.- Specified by:
getChannelin interfaceChannelPool- 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.InterruptedExceptionDescription copied from interface:ChannelPoolRetrieves a channel from the pool after blocking the thread for a delay period defined by theRecoveryDelayHandlerof the connection for this pool.- Specified by:
getChannelWithRecoveringDelayin interfaceChannelPool- 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 errorjava.lang.InterruptedException- if the thread was interrupted during the delay period
-
isTopologyRecoveryEnabled
public boolean isTopologyRecoveryEnabled()
Description copied from interface:ChannelPoolReturns whethertopology recoveryis enabled for the connection of this pool.- Specified by:
isTopologyRecoveryEnabledin interfaceChannelPool- Returns:
- true by default
-
returnChannel
public void returnChannel(com.rabbitmq.client.Channel channel)
Description copied from interface:ChannelPoolReturns a channel to the pool. No further use of the channel is allowed by the returner.- Specified by:
returnChannelin interfaceChannelPool- Parameters:
channel- The channel
-
createChannel
protected com.rabbitmq.client.Channel createChannel() throws java.io.IOExceptionCreates 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:
closein interfacejava.lang.AutoCloseable
-
-