Interface RabbitMQConnection
- All Known Implementing Classes:
RabbitMQConnectionImpl
public interface RabbitMQConnection
Represents a managed RabbitMQ connection with channel pooling support.
Connections are configured via .properties files referenced by the
CONNECTOR_RABBITMQ_<ID>_CONFIG environment variable. Supported properties:
host— broker hostname (default:localhost)port— broker port (default:5672)username— authentication username (default:guest)password— authentication password (default:guest)virtualHost— virtual host (default:/)ssl— enable SSL with default JVM SSLContext (default:false)channelPoolSize— fixed channel pool size (default:5)
Channels are managed through a fixed-size pool. Use borrowChannel() to obtain
a PooledChannel that automatically returns to the pool when closed:
try (var channel = connection.borrowChannel()) {
channel.basicPublish("exchange", "key", null, "message".getBytes());
}
- See Also:
-
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.
-
Method Details
-
getConnection
Returns the underlying RabbitMQ connection.- Returns:
- the raw
Connectioninstance - Throws:
NullPointerException- if called beforeinit()
-
borrowChannel
Borrows 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.- Returns:
- a pooled channel wrapper
- Throws:
InterruptedException- if the current thread is interrupted while waiting for a channel
-
init
Initializes the RabbitMQ connection and pre-creates the channel pool.- Throws:
ConnectionInitException- if the connection or channel pool creation fails
-
shutdown
void shutdown()Shuts down the connection, closing all pooled channels and the underlying connection. -
isExitOnFailure
boolean isExitOnFailure()Returns whether this connection is configured to cause server shutdown on initialization failure.- Returns:
trueif the server should exit when this connection fails to initialize
-