Package io.micronaut.rabbitmq.connect
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
-
Field Summary
Fields inherited from interface io.micronaut.rabbitmq.connect.ChannelPool
DEFAULT_RECOVERY_DELAY -
Constructor Summary
ConstructorsConstructorDescriptionDefaultChannelPool(String name, com.rabbitmq.client.Connection connection, RabbitConnectionFactoryConfig config) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected com.rabbitmq.client.ChannelCreates a channel.com.rabbitmq.client.ChannelRetrieves 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.getName()booleanReturns whethertopology recoveryis enabled for the connection of this pool.voidreturnChannel(com.rabbitmq.client.Channel channel) Returns a channel to the pool.
-
Constructor Details
-
DefaultChannelPool
public DefaultChannelPool(@Parameter 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 Details
-
getName
- Specified by:
getNamein interfaceio.micronaut.core.naming.Named
-
getChannel
Description 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:
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: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:
IOException- if a channel needed to be created and encountered an errorInterruptedException- 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
Creates a channel.- Returns:
- The newly created channel
- Throws:
IOException- If an error occurred creating the channel
-
close
@PreDestroy public void close()- Specified by:
closein interfaceAutoCloseable
-