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
ConstructorDescriptionDefaultChannelPool
(String name, com.rabbitmq.client.Connection connection, RabbitConnectionFactoryConfig config) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected com.rabbitmq.client.Channel
Creates a channel.com.rabbitmq.client.Channel
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 theRecoveryDelayHandler
of the connection for this pool.getName()
boolean
Returns whethertopology recovery
is enabled for the connection of this pool.void
returnChannel
(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:
getName
in interfaceio.micronaut.core.naming.Named
-
getChannel
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 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:ChannelPool
Retrieves a channel from the pool after blocking the thread for a delay period defined by theRecoveryDelayHandler
of the connection for this pool.- Specified by:
getChannelWithRecoveringDelay
in 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:ChannelPool
Returns whethertopology recovery
is enabled for the connection of this pool.- Specified by:
isTopologyRecoveryEnabled
in interfaceChannelPool
- 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 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:
close
in interfaceAutoCloseable
-