@Singleton
public class CdiConnectionFactory
extends com.rabbitmq.client.ConnectionFactory
A single connection factory provides ONE SINGLE connection to a RabbitMQ message broker via TCP.
It is recommended by the RabbitMQ documentation (v2.7) to use one single connection within a client and to use one channel for every client thread.
| Modifier and Type | Field and Description |
|---|---|
static int |
CONNECTION_ESTABLISH_INTERVAL_IN_MS |
static int |
CONNECTION_HEARTBEAT_IN_SEC |
static int |
CONNECTION_TIMEOUT_IN_MS |
| Constructor and Description |
|---|
CdiConnectionFactory() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection factory and interrupts all threads associated to it.
|
com.rabbitmq.client.Connection |
newConnection()
Gets a new connection from the factory.
|
void |
registerListener(ConnectionListener connectionListener)
Registers a connection listener at the factory which is notified about changes of connection
states.
|
void |
removeConnectionListener(ConnectionListener connectionListener)
Removes a connection listener from the factory.
|
clone, createFrameHandlerFactory, getClientProperties, getConnectionTimeout, getExceptionHandler, getHost, getNetworkRecoveryInterval, getPassword, getPort, getRequestedChannelMax, getRequestedFrameMax, getRequestedHeartbeat, getSaslConfig, getShutdownTimeout, getSocketConfigurator, getSocketFactory, getThreadFactory, getUsername, getVirtualHost, isAutomaticRecoveryEnabled, isSSL, isTopologyRecoveryEnabled, newConnection, newConnection, newConnection, params, portOrDefault, setAutomaticRecoveryEnabled, setClientProperties, setConnectionTimeout, setExceptionHandler, setHost, setNetworkRecoveryInterval, setNetworkRecoveryInterval, setPassword, setPort, setRequestedChannelMax, setRequestedFrameMax, setRequestedHeartbeat, setSaslConfig, setSharedExecutor, setShutdownTimeout, setSocketConfigurator, setSocketFactory, setThreadFactory, setTopologyRecoveryEnabled, setUri, setUri, setUsername, setVirtualHost, useSslProtocol, useSslProtocol, useSslProtocol, useSslProtocolpublic static final int CONNECTION_HEARTBEAT_IN_SEC
public static final int CONNECTION_TIMEOUT_IN_MS
public static final int CONNECTION_ESTABLISH_INTERVAL_IN_MS
public com.rabbitmq.client.Connection newConnection()
throws java.io.IOException,
java.util.concurrent.TimeoutException
Gets a new connection from the factory. As this factory only provides one connection for every process, the connection is established on the first call of this method. Every subsequent call will return the same instance of the first established connection.
In case a connection is lost, the factory will try to reestablish a new connection.
newConnection in class com.rabbitmq.client.ConnectionFactoryjava.io.IOExceptionjava.util.concurrent.TimeoutException@PreDestroy public void close()
Closes the connection factory and interrupts all threads associated to it.
Note: Make sure to close the connection factory when not used any more as otherwise the connection may remain established and ghost threads may reside.
public void registerListener(ConnectionListener connectionListener)
connectionListener - The connection listenerpublic void removeConnectionListener(ConnectionListener connectionListener)
connectionListener - The connection listener