Class RabbitMQConnectionImpl
java.lang.Object
fr.codinbox.connector.commons.rabbitmq.RabbitMQConnectionImpl
- All Implemented Interfaces:
RabbitMQConnection
Implementation of
RabbitMQConnection that manages a RabbitMQ connection
and a fixed-size channel pool.
The channel pool is pre-populated at initialization time. Channels are borrowed
and returned via PooledChannel, which implements AutoCloseable.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionBorrows a channel from the fixed-size pool.Returns the underlying RabbitMQ connection.voidinit()Initializes the RabbitMQ connection and pre-creates the channel pool.booleanReturns whether this connection is configured to cause server shutdown on initialization failure.voidshutdown()Shuts down the connection, closing all pooled channels and the underlying connection.
-
Constructor Details
-
RabbitMQConnectionImpl
public RabbitMQConnectionImpl(@NotNull @NotNull Logger logger, @NotNull @NotNull String id, @NotNull @NotNull String configFilePath) Creates a new RabbitMQ connection instance.- Parameters:
logger- the logger for diagnostic messagesid- the connection identifierconfigFilePath- the path to the.propertiesconfiguration file
-
-
Method Details
-
init
Description copied from interface:RabbitMQConnectionInitializes the RabbitMQ connection and pre-creates the channel pool.- Specified by:
initin interfaceRabbitMQConnection- Throws:
ConnectionInitException- if the connection or channel pool creation fails
-
shutdown
public void shutdown()Description copied from interface:RabbitMQConnectionShuts down the connection, closing all pooled channels and the underlying connection.- Specified by:
shutdownin interfaceRabbitMQConnection
-
getConnection
Description copied from interface:RabbitMQConnectionReturns the underlying RabbitMQ connection.- Specified by:
getConnectionin interfaceRabbitMQConnection- Returns:
- the raw
Connectioninstance
-
borrowChannel
Description copied from interface:RabbitMQConnectionBorrows a channel from the fixed-size pool.The returned
PooledChannelimplementsAutoCloseableand should be used in a try-with-resources block to ensure the channel is returned to the pool.- Specified by:
borrowChannelin interfaceRabbitMQConnection- Returns:
- a pooled channel wrapper
- Throws:
InterruptedException- if the current thread is interrupted while waiting for a channel
-
isExitOnFailure
public boolean isExitOnFailure()Description copied from interface:RabbitMQConnectionReturns whether this connection is configured to cause server shutdown on initialization failure.- Specified by:
isExitOnFailurein interfaceRabbitMQConnection- Returns:
trueif the server should exit when this connection fails to initialize
-