public class ConnectionFactory extends Object implements Cloneable
Connection
to a RabbitMQ node.
Most connection and socket settings are configured using this factory.
Some settings that apply to connections can also be configured here
and will apply to all connections produced by this factory.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_AMQP_OVER_SSL_PORT
The default ssl port
|
static int |
DEFAULT_AMQP_PORT
The default non-ssl port
|
static int |
DEFAULT_CHANNEL_MAX
Default maximum channel number;
2047 because it's 2048 on the server side minus channel 0,
which each connection uses for negotiation
and error communication
|
static int |
DEFAULT_CHANNEL_RPC_TIMEOUT
The default continuation timeout for RPC calls in channels: 10 minutes
|
static int |
DEFAULT_CONNECTION_TIMEOUT
The default TCP connection timeout: 60 seconds
|
static int |
DEFAULT_FRAME_MAX
Default maximum frame size;
zero means no limit
|
static int |
DEFAULT_HANDSHAKE_TIMEOUT
The default AMQP 0-9-1 connection handshake timeout.
|
static int |
DEFAULT_HEARTBEAT
Default heart-beat interval;
60 seconds
|
static String |
DEFAULT_HOST
The default host
|
static long |
DEFAULT_NETWORK_RECOVERY_INTERVAL
The default network recovery interval: 5000 millis
|
static String |
DEFAULT_PASS
Default password
|
static int |
DEFAULT_SHUTDOWN_TIMEOUT
The default shutdown timeout;
zero means wait indefinitely
|
static String |
DEFAULT_USER
Default user name
|
static String |
DEFAULT_VHOST
Default virtual host
|
static int |
DEFAULT_WORK_POOL_TIMEOUT
The default timeout for work pool enqueueing: no timeout
|
static int |
USE_DEFAULT_PORT
'Use the default port' port
|
Constructor and Description |
---|
ConnectionFactory() |
Modifier and Type | Method and Description |
---|---|
ConnectionFactory |
clone() |
static String |
computeDefaultTlsProtocol(String[] supportedProtocols) |
protected AddressResolver |
createAddressResolver(List<Address> addresses) |
protected AMQConnection |
createConnection(ConnectionParams params,
FrameHandler frameHandler,
MetricsCollector metricsCollector) |
protected FrameHandlerFactory |
createFrameHandlerFactory() |
void |
enableHostnameVerification()
Enable server hostname verification for TLS connections.
|
protected void |
enableHostnameVerificationForBlockingIo() |
protected void |
enableHostnameVerificationForNio() |
static int |
ensureUnsignedShort(int value) |
int |
getChannelRpcTimeout()
Get the timeout for RPC calls in channels.
|
Map<String,Object> |
getClientProperties()
Retrieve the currently-configured table of client properties
that will be sent to the server during connection
startup.
|
int |
getConnectionTimeout()
Retrieve the TCP connection timeout.
|
ExceptionHandler |
getExceptionHandler()
Get the exception handler.
|
int |
getHandshakeTimeout()
Retrieve the AMQP 0-9-1 protocol handshake timeout.
|
String |
getHost() |
MetricsCollector |
getMetricsCollector() |
long |
getNetworkRecoveryInterval()
Returns automatic connection recovery interval in milliseconds.
|
NioParams |
getNioParams()
Retrieve the parameters for NIO mode.
|
String |
getPassword()
Retrieve the password.
|
int |
getPort() |
RecoveryDelayHandler |
getRecoveryDelayHandler()
Returns automatic connection recovery delay handler.
|
int |
getRequestedChannelMax()
Retrieve the requested maximum channel number
|
int |
getRequestedFrameMax()
Retrieve the requested maximum frame size
|
int |
getRequestedHeartbeat()
Retrieve the requested heartbeat interval.
|
SaslConfig |
getSaslConfig()
Gets the sasl config to use when authenticating
|
int |
getShutdownTimeout()
Retrieve the shutdown timeout.
|
SocketConfigurator |
getSocketConfigurator()
Get the socket configurator.
|
SocketFactory |
getSocketFactory()
Retrieve the socket factory used to make connections with.
|
ThreadFactory |
getThreadFactory()
Retrieve the thread factory used to instantiate new threads.
|
ExecutorService |
getTopologyRecoveryExecutor()
Get the executor to use for parallel topology recovery.
|
String |
getUsername()
Retrieve the user name.
|
String |
getVirtualHost()
Retrieve the virtual host.
|
int |
getWorkPoolTimeout() |
boolean |
isAutomaticRecoveryEnabled()
Returns true if automatic connection recovery
is enabled, false otherwise
|
boolean |
isChannelShouldCheckRpcResponseType() |
boolean |
isSSL() |
boolean |
isTopologyRecoveryEnabled()
Returns true if topology recovery is enabled, false otherwise
|
ConnectionFactory |
load(Map<String,String> properties)
Load settings from a
Map instance. |
ConnectionFactory |
load(Map<String,String> properties,
String prefix)
Load settings from a
Map instance. |
ConnectionFactory |
load(Properties properties)
Load settings from a
Properties instance. |
ConnectionFactory |
load(Properties properties,
String prefix)
Load settings from a
Properties instance. |
ConnectionFactory |
load(String propertyFileLocation)
Load settings from a property file.
|
ConnectionFactory |
load(String propertyFileLocation,
String prefix)
Load settings from a property file.
|
Connection |
newConnection()
Create a new broker connection.
|
Connection |
newConnection(Address[] addrs)
Create a new broker connection, picking the first available address from
the list.
|
Connection |
newConnection(Address[] addrs,
String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from
the list.
|
Connection |
newConnection(AddressResolver addressResolver)
Create a new broker connection, picking the first available address from
the list provided by the
AddressResolver . |
Connection |
newConnection(ExecutorService executor)
Create a new broker connection.
|
Connection |
newConnection(ExecutorService executor,
Address[] addrs)
Create a new broker connection, picking the first available address from
the list.
|
Connection |
newConnection(ExecutorService executor,
Address[] addrs,
String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from
the list.
|
Connection |
newConnection(ExecutorService executor,
AddressResolver addressResolver)
Create a new broker connection, picking the first available address from
the list provided by the
AddressResolver . |
Connection |
newConnection(ExecutorService executor,
AddressResolver addressResolver,
String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from
the list provided by the
AddressResolver . |
Connection |
newConnection(ExecutorService executor,
List<Address> addrs)
Create a new broker connection, picking the first available address from
the list.
|
Connection |
newConnection(ExecutorService executor,
List<Address> addrs,
String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from
the list.
|
Connection |
newConnection(ExecutorService executor,
String connectionName)
Create a new broker connection.
|
Connection |
newConnection(List<Address> addrs)
Create a new broker connection, picking the first available address from
the list.
|
Connection |
newConnection(List<Address> addrs,
String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from
the list.
|
Connection |
newConnection(String connectionName)
Create a new broker connection.
|
ConnectionParams |
params(ExecutorService consumerWorkServiceExecutor) |
static int |
portOrDefault(int port,
boolean ssl) |
protected void |
processUriQueryParameter(String key,
String value)
Hook to process query parameters not handled natively.
|
void |
setAutomaticRecoveryEnabled(boolean automaticRecovery)
Enables or disables automatic connection recovery.
|
void |
setChannelRpcTimeout(int channelRpcTimeout)
Set the continuation timeout for RPC calls in channels.
|
void |
setChannelShouldCheckRpcResponseType(boolean channelShouldCheckRpcResponseType)
When set to true, channels will check the response type (e.g.
|
void |
setClientProperties(Map<String,Object> clientProperties)
Replace the table of client properties that will be sent to the
server during subsequent connection startups.
|
void |
setConnectionRecoveryTriggeringCondition(Predicate<ShutdownSignalException> connectionRecoveryTriggeringCondition)
Allows to decide on automatic connection recovery is triggered.
|
void |
setConnectionTimeout(int timeout)
Set the TCP connection timeout.
|
void |
setCredentialsProvider(CredentialsProvider credentialsProvider)
Set a custom credentials provider.
|
void |
setCredentialsRefreshService(CredentialsRefreshService credentialsRefreshService)
Set a
CredentialsRefreshService instance to handle credentials refresh if appropriate. |
void |
setErrorOnWriteListener(ErrorOnWriteListener errorOnWriteListener)
Set a listener to be called when connection gets an IO error trying to write on the socket.
|
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Set the exception handler to use for newly created connections.
|
void |
setHandshakeTimeout(int timeout)
Set the AMQP0-9-1 protocol handshake timeout.
|
void |
setHeartbeatExecutor(ScheduledExecutorService executor)
Set the executor to use to send heartbeat frames.
|
void |
setHost(String host) |
void |
setMetricsCollector(MetricsCollector metricsCollector) |
void |
setNetworkRecoveryInterval(int networkRecoveryInterval)
Sets connection recovery interval.
|
void |
setNetworkRecoveryInterval(long networkRecoveryInterval)
Sets connection recovery interval.
|
void |
setNioParams(NioParams nioParams)
Sets the parameters when using NIO.
|
void |
setPassword(String password)
Set the password.
|
void |
setPort(int port)
Set the target port.
|
void |
setRecoveredQueueNameSupplier(RecoveredQueueNameSupplier recoveredQueueNameSupplier)
Set the recovered queue name supplier.
|
void |
setRecoveryDelayHandler(RecoveryDelayHandler recoveryDelayHandler)
Sets the automatic connection recovery delay handler.
|
void |
setRequestedChannelMax(int requestedChannelMax)
Set the requested maximum channel number.
|
void |
setRequestedFrameMax(int requestedFrameMax)
Set the requested maximum frame size
|
void |
setRequestedHeartbeat(int requestedHeartbeat)
Set the requested heartbeat timeout.
|
void |
setSaslConfig(SaslConfig saslConfig)
Sets the sasl config to use when authenticating
|
void |
setSharedExecutor(ExecutorService executor)
Set the executor to use for consumer operation dispatch
by default for newly created connections.
|
void |
setShutdownExecutor(ExecutorService executor)
Set the executor to use for connection shutdown.
|
void |
setShutdownTimeout(int shutdownTimeout)
Set the shutdown timeout.
|
void |
setSocketConfigurator(SocketConfigurator socketConfigurator)
Set the socket configurator.
|
void |
setSocketFactory(SocketFactory factory)
Set the socket factory used to create sockets for new connections.
|
void |
setSslContextFactory(SslContextFactory sslContextFactory)
The factory to create SSL contexts.
|
void |
setThreadFactory(ThreadFactory threadFactory)
Set the thread factory used to instantiate new threads.
|
void |
setTopologyRecoveryEnabled(boolean topologyRecovery)
Enables or disables topology recovery
|
void |
setTopologyRecoveryExecutor(ExecutorService topologyRecoveryExecutor)
Set the executor to use for parallel topology recovery.
|
void |
setTopologyRecoveryFilter(TopologyRecoveryFilter topologyRecoveryFilter)
Set filter to include/exclude entities from topology recovery.
|
void |
setTopologyRecoveryRetryHandler(RetryHandler topologyRecoveryRetryHandler)
Set retry handler for topology recovery.
|
void |
setTrafficListener(TrafficListener trafficListener)
Traffic listener notified of inbound and outbound
Command s. |
void |
setUri(String uriString)
Convenience method for setting the fields in an AMQP URI: host,
port, username, password and virtual host.
|
void |
setUri(URI uri)
Convenience method for setting the fields in an AMQP URI: host,
port, username, password and virtual host.
|
void |
setUsername(String username)
Set the user name.
|
void |
setVirtualHost(String virtualHost)
Set the virtual host.
|
void |
setWorkPoolTimeout(int workPoolTimeout)
Timeout (in ms) for work pool enqueueing.
|
void |
useBlockingIo()
Use blocking IO for communication with the server.
|
void |
useNio()
Use non-blocking IO (NIO) for communication with the server.
|
void |
useSslProtocol()
Convenience method for configuring TLS using
the default set of TLS protocols and a trusting TrustManager.
|
void |
useSslProtocol(SSLContext context)
Sets up TLS with an initialized
SSLContext . |
void |
useSslProtocol(String protocol)
Convenience method for configuring TLS using
the supplied protocol and a very trusting TrustManager.
|
void |
useSslProtocol(String protocol,
TrustManager trustManager)
Convenience method for configuring TLS.
|
public static final String DEFAULT_USER
public static final String DEFAULT_PASS
public static final String DEFAULT_VHOST
public static final int DEFAULT_CHANNEL_MAX
public static final int DEFAULT_FRAME_MAX
public static final int DEFAULT_HEARTBEAT
public static final String DEFAULT_HOST
public static final int USE_DEFAULT_PORT
public static final int DEFAULT_AMQP_PORT
public static final int DEFAULT_AMQP_OVER_SSL_PORT
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_HANDSHAKE_TIMEOUT
public static final int DEFAULT_SHUTDOWN_TIMEOUT
public static final int DEFAULT_CHANNEL_RPC_TIMEOUT
public static final long DEFAULT_NETWORK_RECOVERY_INTERVAL
public static final int DEFAULT_WORK_POOL_TIMEOUT
public String getHost()
public void setHost(String host)
host
- the default host to use for connectionspublic static int portOrDefault(int port, boolean ssl)
public int getPort()
public void setPort(int port)
port
- the default port to use for connectionspublic String getUsername()
public void setUsername(String username)
username
- the AMQP user name to use when connecting to the brokerpublic String getPassword()
public void setPassword(String password)
password
- the password to use when connecting to the brokerpublic void setCredentialsProvider(CredentialsProvider credentialsProvider)
credentialsProvider
- The custom implementation of CredentialsProvider to use when connecting to the broker.DefaultCredentialsProvider
public String getVirtualHost()
public void setVirtualHost(String virtualHost)
virtualHost
- the virtual host to use when connecting to the brokerpublic void setUri(URI uri) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException
uri
- is the AMQP URI containing the dataURISyntaxException
NoSuchAlgorithmException
KeyManagementException
public void setUri(String uriString) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException
uriString
- is the AMQP URI containing the dataURISyntaxException
NoSuchAlgorithmException
KeyManagementException
protected void processUriQueryParameter(String key, String value)
heartbeat
, connection_timeout
,
channel_max
.key
- value
- public int getRequestedChannelMax()
public void setRequestedChannelMax(int requestedChannelMax)
Note the value must be between 0 and 65535 (unsigned short in AMQP 0-9-1).
requestedChannelMax
- initially requested maximum channel number; zero for unlimitedpublic int getRequestedFrameMax()
public void setRequestedFrameMax(int requestedFrameMax)
requestedFrameMax
- initially requested maximum frame size, in octets; zero for unlimitedpublic int getRequestedHeartbeat()
public void setConnectionTimeout(int timeout)
timeout
- connection TCP establishment timeout in milliseconds; zero for infinitepublic int getConnectionTimeout()
public int getHandshakeTimeout()
public void setHandshakeTimeout(int timeout)
timeout
- the AMQP0-9-1 protocol handshake timeout, in millisecondspublic void setShutdownTimeout(int shutdownTimeout)
shutdownTimeout
- shutdown timeout in milliseconds; zero for infinite; default 10000public int getShutdownTimeout()
public void setRequestedHeartbeat(int requestedHeartbeat)
Note the value must be between 0 and 65535 (unsigned short in AMQP 0-9-1).
requestedHeartbeat
- the initially requested heartbeat timeout, in seconds; zero for nonepublic Map<String,Object> getClientProperties()
setClientProperties(java.util.Map<java.lang.String, java.lang.Object>)
public void setClientProperties(Map<String,Object> clientProperties)
clientProperties
- the map of extra client propertiesgetClientProperties()
public SaslConfig getSaslConfig()
SaslConfig
public void setSaslConfig(SaslConfig saslConfig)
saslConfig
- SaslConfig
public SocketFactory getSocketFactory()
public void setSocketFactory(SocketFactory factory)
useSslProtocol()
public SocketConfigurator getSocketConfigurator()
public void setSocketConfigurator(SocketConfigurator socketConfigurator)
socketConfigurator
- the configurator to usepublic void setSharedExecutor(ExecutorService executor)
executor
- executor service to be used for
consumer operationpublic void setShutdownExecutor(ExecutorService executor)
executor
- executor service to be used for
connection shutdownpublic void setHeartbeatExecutor(ScheduledExecutorService executor)
executor
- executor service to be used to send heartbeatpublic ThreadFactory getThreadFactory()
ThreadFactory
public void setThreadFactory(ThreadFactory threadFactory)
ThreadFactory
public ExceptionHandler getExceptionHandler()
ExceptionHandler
public void setExceptionHandler(ExceptionHandler exceptionHandler)
ExceptionHandler
public boolean isSSL()
public void useSslProtocol() throws NoSuchAlgorithmException, KeyManagementException
useSslProtocol(SSLContext)
.public void useSslProtocol(String protocol) throws NoSuchAlgorithmException, KeyManagementException
useSslProtocol(SSLContext)
in production environments.
The produced SSLContext
instance will be shared by all
the connections created by this connection factory.
Use setSslContextFactory(SslContextFactory)
for more flexibility.public void useSslProtocol(String protocol, TrustManager trustManager) throws NoSuchAlgorithmException, KeyManagementException
TrustManager
.
The produced SSLContext
instance will be shared with all
the connections created by this connection factory. Use
setSslContextFactory(SslContextFactory)
for more flexibility.protocol
- the TLS protocol to use.trustManager
- the TrustManager
implementation to use.NoSuchAlgorithmException
KeyManagementException
setSslContextFactory(SslContextFactory)
,
useSslProtocol(SSLContext)
public void useSslProtocol(SSLContext context)
SSLContext
. The caller is responsible
for setting up the context with a TrustManager
with suitable security guarantees,
e.g. peer verification.
The SSLContext
instance will be shared with all
the connections created by this connection factory. Use
setSslContextFactory(SslContextFactory)
for more flexibility.context
- An initialized SSLContextsetSslContextFactory(SslContextFactory)
public void enableHostnameVerification()
This enables hostname verification regardless of the IO mode used (blocking or non-blocking IO).
This can be called typically after setting the SSLContext
with one of the useSslProtocol
methods.
NioParams.enableHostnameVerification()
,
NioParams.setSslEngineConfigurator(SslEngineConfigurator)
,
SslEngineConfigurators.ENABLE_HOSTNAME_VERIFICATION
,
SocketConfigurators.ENABLE_HOSTNAME_VERIFICATION
,
useSslProtocol(String)
,
useSslProtocol(SSLContext)
,
useSslProtocol()
,
useSslProtocol(String, TrustManager)
protected void enableHostnameVerificationForNio()
protected void enableHostnameVerificationForBlockingIo()
public static String computeDefaultTlsProtocol(String[] supportedProtocols)
public boolean isAutomaticRecoveryEnabled()
public void setAutomaticRecoveryEnabled(boolean automaticRecovery)
automaticRecovery
- if true, enables connection recoverypublic boolean isTopologyRecoveryEnabled()
public void setTopologyRecoveryEnabled(boolean topologyRecovery)
topologyRecovery
- if true, enables topology recoverypublic ExecutorService getTopologyRecoveryExecutor()
public void setTopologyRecoveryExecutor(ExecutorService topologyRecoveryExecutor)
ExceptionHandler.handleTopologyRecoveryException(Connection, Channel, TopologyRecoveryException)
method should be thread-safe.topologyRecoveryExecutor
- thread pool executorpublic void setMetricsCollector(MetricsCollector metricsCollector)
public MetricsCollector getMetricsCollector()
public void setCredentialsRefreshService(CredentialsRefreshService credentialsRefreshService)
CredentialsRefreshService
instance to handle credentials refresh if appropriate.
Each created connection will register to the refresh service to send an AMQP update.secret
frame when credentials are about to expire. This is the refresh service responsibility to schedule
credentials refresh and udpate.secret
frame sending, based on the information provided
by the CredentialsProvider
.
Note the CredentialsRefreshService
is used only when the CredentialsProvider
signals credentials can expire, by returning a non-null value from CredentialsProvider.getTimeBeforeExpiration()
.
credentialsRefreshService
- the refresh service to usesetCredentialsProvider(CredentialsProvider)
,
DefaultCredentialsRefreshService
protected FrameHandlerFactory createFrameHandlerFactory() throws IOException
IOException
public Connection newConnection(Address[] addrs) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.addrs
- an array of known broker addresses (hostname/port pairs) to try in orderIOException
- if it encounters a problemTimeoutException
public Connection newConnection(AddressResolver addressResolver) throws IOException, TimeoutException
AddressResolver
.
If automatic connection recovery
is enabled, the connection returned by this method will be Recoverable
. Future
reconnection attempts will pick a random accessible address provided by the AddressResolver
.addressResolver
- discovery service to list potential addresses (hostname/port pairs) to connect toIOException
- if it encounters a problemTimeoutException
public Connection newConnection(Address[] addrs, String clientProvidedName) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.addrs
- an array of known broker addresses (hostname/port pairs) to try in orderclientProvidedName
- application-specific connection name, will be displayed
in the management UI if RabbitMQ server supports it.
This value doesn't have to be unique and cannot be used
as a connection identifier e.g. in HTTP API requests.
This value is supposed to be human-readable.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(List<Address> addrs) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.addrs
- a List of known broker addresses (hostname/port pairs) to try in orderIOException
- if it encounters a problemTimeoutException
public Connection newConnection(List<Address> addrs, String clientProvidedName) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.addrs
- a List of known broker addresses (hostname/port pairs) to try in orderclientProvidedName
- application-specific connection name, will be displayed
in the management UI if RabbitMQ server supports it.
This value doesn't have to be unique and cannot be used
as a connection identifier e.g. in HTTP API requests.
This value is supposed to be human-readable.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, Address[] addrs) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.executor
- thread execution service for consumers on the connectionaddrs
- an array of known broker addresses (hostname/port pairs) to try in orderIOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, Address[] addrs, String clientProvidedName) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.executor
- thread execution service for consumers on the connectionaddrs
- an array of known broker addresses (hostname/port pairs) to try in orderclientProvidedName
- application-specific connection name, will be displayed
in the management UI if RabbitMQ server supports it.
This value doesn't have to be unique and cannot be used
as a connection identifier e.g. in HTTP API requests.
This value is supposed to be human-readable.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, List<Address> addrs) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.executor
- thread execution service for consumers on the connectionaddrs
- a List of known broker addrs (hostname/port pairs) to try in orderIOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, AddressResolver addressResolver) throws IOException, TimeoutException
AddressResolver
.
If automatic connection recovery
is enabled, the connection returned by this method will be Recoverable
. Future
reconnection attempts will pick a random accessible address provided by the AddressResolver
.executor
- thread execution service for consumers on the connectionaddressResolver
- discovery service to list potential addresses (hostname/port pairs) to connect toIOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, List<Address> addrs, String clientProvidedName) throws IOException, TimeoutException
Recoverable
. Future
reconnection attempts will pick a random accessible address from the provided list.executor
- thread execution service for consumers on the connectionaddrs
- a List of known broker addrs (hostname/port pairs) to try in orderclientProvidedName
- application-specific connection name, will be displayed
in the management UI if RabbitMQ server supports it.
This value doesn't have to be unique and cannot be used
as a connection identifier e.g. in HTTP API requests.
This value is supposed to be human-readable.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, AddressResolver addressResolver, String clientProvidedName) throws IOException, TimeoutException
AddressResolver
.
If automatic connection recovery
is enabled, the connection returned by this method will be Recoverable
. Future
reconnection attempts will pick a random accessible address provided by the AddressResolver
.executor
- thread execution service for consumers on the connectionaddressResolver
- discovery service to list potential addresses (hostname/port pairs) to connect toclientProvidedName
- application-specific connection name, will be displayed
in the management UI if RabbitMQ server supports it.
This value doesn't have to be unique and cannot be used
as a connection identifier e.g. in HTTP API requests.
This value is supposed to be human-readable.IOException
- if it encounters a problemTimeoutException
public ConnectionParams params(ExecutorService consumerWorkServiceExecutor)
protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector)
public Connection newConnection() throws IOException, TimeoutException
Recoverable
. Reconnection
attempts will always use the address configured on ConnectionFactory
.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(String connectionName) throws IOException, TimeoutException
Recoverable
. Reconnection
attempts will always use the address configured on ConnectionFactory
.connectionName
- client-provided connection name (an arbitrary string). Will
be displayed in management UI if the server supports it.IOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor) throws IOException, TimeoutException
Recoverable
. Reconnection
attempts will always use the address configured on ConnectionFactory
.executor
- thread execution service for consumers on the connectionIOException
- if it encounters a problemTimeoutException
public Connection newConnection(ExecutorService executor, String connectionName) throws IOException, TimeoutException
Recoverable
. Reconnection
attempts will always use the address configured on ConnectionFactory
.executor
- thread execution service for consumers on the connectionconnectionName
- client-provided connection name (an arbitrary string). Will
be displayed in management UI if the server supports it.IOException
- if it encounters a problemTimeoutException
protected AddressResolver createAddressResolver(List<Address> addresses)
public ConnectionFactory clone()
public ConnectionFactory load(String propertyFileLocation) throws IOException
rabbitmq.
,
use load(String, String)
to
specify your own prefix.propertyFileLocation
- location of the property file to useIOException
- when something goes wrong reading the fileConnectionFactoryConfigurator
public ConnectionFactory load(String propertyFileLocation, String prefix) throws IOException
propertyFileLocation
- location of the property file to useprefix
- key prefix for the entries in the fileIOException
- when something goes wrong reading the fileConnectionFactoryConfigurator
public ConnectionFactory load(Properties properties)
Properties
instance.
Keys must be prefixed with rabbitmq.
,
use load(Properties, String)
to
specify your own prefix.properties
- source for settingsConnectionFactoryConfigurator
public ConnectionFactory load(Properties properties, String prefix)
Properties
instance.properties
- source for settingsprefix
- key prefix for properties entriesConnectionFactoryConfigurator
public ConnectionFactory load(Map<String,String> properties)
Map
instance.
Keys must be prefixed with rabbitmq.
,
use load(Map, String)
to
specify your own prefix.properties
- source for settingsConnectionFactoryConfigurator
public ConnectionFactory load(Map<String,String> properties, String prefix)
Map
instance.properties
- source for settingsprefix
- key prefix for map entriesConnectionFactoryConfigurator
public long getNetworkRecoveryInterval()
public void setNetworkRecoveryInterval(int networkRecoveryInterval)
RecoveryDelayHandler.DefaultRecoveryDelayHandler
by default.
Use another RecoveryDelayHandler
implementation for more flexibility.networkRecoveryInterval
- how long will automatic recovery wait before attempting to reconnect, in msRecoveryDelayHandler
public void setNetworkRecoveryInterval(long networkRecoveryInterval)
RecoveryDelayHandler.DefaultRecoveryDelayHandler
by default.
Use another RecoveryDelayHandler
implementation for more flexibility.networkRecoveryInterval
- how long will automatic recovery wait before attempting to reconnect, in msRecoveryDelayHandler
public RecoveryDelayHandler getRecoveryDelayHandler()
public void setRecoveryDelayHandler(RecoveryDelayHandler recoveryDelayHandler)
recoveryDelayHandler
- the recovery delay handlerpublic void setNioParams(NioParams nioParams)
nioParams
- NioParams
public NioParams getNioParams()
public void useNio()
ConnectionFactory
can use the same IO thread.
A client process using a lot of not-so-active connections can benefit
from NIO, as it would use fewer threads than with the traditional, blocking IO mode.
Use NioParams
to tune NIO and a SocketChannelConfigurator
to
configure the underlying SocketChannel
s for connections.NioParams
,
SocketChannelConfigurator
,
SocketChannel
,
Selector
public void useBlockingIo()
public void setChannelRpcTimeout(int channelRpcTimeout)
channelRpcTimeout
- public int getChannelRpcTimeout()
public void setSslContextFactory(SslContextFactory sslContextFactory)
SSLContext
s
for different connections than sharing the SSLContext
with all the connections produced by the connection factory
(which is the case with the useSslProtocol()
methods).
This way, different connections with a different certificate
for each of them is a possible scenario.sslContextFactory
- useSslProtocol(SSLContext)
public void setChannelShouldCheckRpcResponseType(boolean channelShouldCheckRpcResponseType)
channelShouldCheckRpcResponseType
- public boolean isChannelShouldCheckRpcResponseType()
public void setWorkPoolTimeout(int workPoolTimeout)
WorkPool
dispatches several types of responses
from the broker (e.g. deliveries). A high-traffic
client with slow consumers can exhaust the work pool and
compromise the whole connection (by e.g. letting the broker
saturate the receive TCP buffers). Setting a timeout
would make the connection fail early and avoid hard-to-diagnose
TCP connection failure. Note this shouldn't happen
with clients that set appropriate QoS values.
Default is no timeout.workPoolTimeout
- timeout in mspublic int getWorkPoolTimeout()
public void setErrorOnWriteListener(ErrorOnWriteListener errorOnWriteListener)
errorOnWriteListener
- the listenerpublic void setTopologyRecoveryFilter(TopologyRecoveryFilter topologyRecoveryFilter)
public void setConnectionRecoveryTriggeringCondition(Predicate<ShutdownSignalException> connectionRecoveryTriggeringCondition)
connectionRecoveryTriggeringCondition
- public void setTopologyRecoveryRetryHandler(RetryHandler topologyRecoveryRetryHandler)
topologyRecoveryRetryHandler
- public void setRecoveredQueueNameSupplier(RecoveredQueueNameSupplier recoveredQueueNameSupplier)
recoveredQueueNameSupplier
- queue name supplierpublic void setTrafficListener(TrafficListener trafficListener)
Command
s.
Useful for debugging purposes, e.g. logging all sent and received messages. Default is no-op.
trafficListener
- TrafficListener
,
LogTrafficListener
public static int ensureUnsignedShort(int value)
Copyright © 2022 VMware, Inc. or its affiliates.. All rights reserved.