Class ConnectionFactory
- java.lang.Object
-
- com.rabbitmq.client.ConnectionFactory
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ConnectionFactory extends java.lang.Object implements java.lang.Cloneable
Convenience factory class to facilitate opening aConnection
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Object>
_clientProperties
private boolean
automaticRecovery
private int
channelRpcTimeout
Continuation timeout on RPC calls.private boolean
channelShouldCheckRpcResponseType
Whether or not channels check the reply type of an RPC call.private java.util.function.Predicate<ShutdownSignalException>
connectionRecoveryTriggeringCondition
Condition to trigger automatic connection recovery.private int
connectionTimeout
private CredentialsProvider
credentialsProvider
private CredentialsRefreshService
credentialsRefreshService
static int
DEFAULT_AMQP_OVER_SSL_PORT
The default ssl portstatic int
DEFAULT_AMQP_PORT
The default non-ssl portstatic 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 communicationstatic int
DEFAULT_CHANNEL_RPC_TIMEOUT
The default continuation timeout for RPC calls in channels: 10 minutesstatic int
DEFAULT_CONNECTION_TIMEOUT
The default TCP connection timeout: 60 secondsstatic int
DEFAULT_FRAME_MAX
Default maximum frame size; zero means no limitstatic int
DEFAULT_HANDSHAKE_TIMEOUT
The default AMQP 0-9-1 connection handshake timeout.static int
DEFAULT_HEARTBEAT
Default heart-beat interval; 60 secondsstatic java.lang.String
DEFAULT_HOST
The default hoststatic long
DEFAULT_NETWORK_RECOVERY_INTERVAL
The default network recovery interval: 5000 millisstatic java.lang.String
DEFAULT_PASS
Default passwordstatic int
DEFAULT_SHUTDOWN_TIMEOUT
The default shutdown timeout; zero means wait indefinitelystatic java.lang.String
DEFAULT_USER
Default user namestatic java.lang.String
DEFAULT_VHOST
Default virtual hoststatic int
DEFAULT_WORK_POOL_TIMEOUT
The default timeout for work pool enqueueing: no timeoutprivate ErrorOnWriteListener
errorOnWriteListener
Listener called when a connection gets an IO error trying to write on the socket.private ExceptionHandler
exceptionHandler
private static java.lang.String
FALLBACK_TLS_PROTOCOL
private FrameHandlerFactory
frameHandlerFactory
private int
handshakeTimeout
private java.util.concurrent.ScheduledExecutorService
heartbeatExecutor
private java.lang.String
host
private static org.slf4j.Logger
LOGGER
private static int
MAX_UNSIGNED_SHORT
private int
maxInboundMessageBodySize
Maximum body size of inbound (received) messages in bytes.private MetricsCollector
metricsCollector
private long
networkRecoveryInterval
private boolean
nio
private NioParams
nioParams
private ObservationCollector
observationCollector
private int
port
private static java.lang.String
PREFERRED_TLS_PROTOCOL
private RecoveredQueueNameSupplier
recoveredQueueNameSupplier
private RecoveryDelayHandler
recoveryDelayHandler
private int
requestedChannelMax
private int
requestedFrameMax
private int
requestedHeartbeat
private SaslConfig
saslConfig
private java.util.concurrent.ExecutorService
sharedExecutor
private java.util.concurrent.ExecutorService
shutdownExecutor
private int
shutdownTimeout
private SocketConfigurator
socketConf
private javax.net.SocketFactory
socketFactory
private SslContextFactory
sslContextFactory
private java.util.concurrent.ThreadFactory
threadFactory
private boolean
topologyRecovery
private java.util.concurrent.ExecutorService
topologyRecoveryExecutor
private TopologyRecoveryFilter
topologyRecoveryFilter
Filter to include/exclude entities from topology recovery.private RetryHandler
topologyRecoveryRetryHandler
Retry handler for topology recovery.private TrafficListener
trafficListener
Traffic listener notified of inbound and outboundCommand
s.private static java.util.Map<java.lang.String,java.util.function.BiConsumer<java.lang.String,ConnectionFactory>>
URI_QUERY_PARAMETER_HANDLERS
static int
USE_DEFAULT_PORT
'Use the default port' portprivate java.lang.String
virtualHost
private int
workPoolTimeout
Timeout in ms for work pool enqueuing.
-
Constructor Summary
Constructors Constructor Description ConnectionFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConnectionFactory
clone()
static java.lang.String
computeDefaultTlsProtocol(java.lang.String[] supportedProtocols)
protected AddressResolver
createAddressResolver(java.util.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.java.util.Map<java.lang.String,java.lang.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.java.lang.String
getHost()
MetricsCollector
getMetricsCollector()
long
getNetworkRecoveryInterval()
Returns automatic connection recovery interval in milliseconds.NioParams
getNioParams()
Retrieve the parameters for NIO mode.java.lang.String
getPassword()
Retrieve the password.int
getPort()
RecoveryDelayHandler
getRecoveryDelayHandler()
Returns automatic connection recovery delay handler.int
getRequestedChannelMax()
Retrieve the requested maximum channel numberint
getRequestedFrameMax()
Retrieve the requested maximum frame sizeint
getRequestedHeartbeat()
Retrieve the requested heartbeat interval.SaslConfig
getSaslConfig()
Gets the sasl config to use when authenticatingint
getShutdownTimeout()
Retrieve the shutdown timeout.SocketConfigurator
getSocketConfigurator()
Get the socket configurator.javax.net.SocketFactory
getSocketFactory()
Retrieve the socket factory used to make connections with.java.util.concurrent.ThreadFactory
getThreadFactory()
Retrieve the thread factory used to instantiate new threads.java.util.concurrent.ExecutorService
getTopologyRecoveryExecutor()
Get the executor to use for parallel topology recovery.java.lang.String
getUsername()
Retrieve the user name.java.lang.String
getVirtualHost()
Retrieve the virtual host.int
getWorkPoolTimeout()
boolean
isAutomaticRecoveryEnabled()
Returns true if automatic connection recovery is enabled, false otherwiseboolean
isChannelShouldCheckRpcResponseType()
boolean
isSSL()
boolean
isTopologyRecoveryEnabled()
Returns true if topology recovery is enabled, false otherwiseConnectionFactory
load(java.lang.String propertyFileLocation)
Load settings from a property file.ConnectionFactory
load(java.lang.String propertyFileLocation, java.lang.String prefix)
Load settings from a property file.ConnectionFactory
load(java.util.Map<java.lang.String,java.lang.String> properties)
Load settings from aMap
instance.ConnectionFactory
load(java.util.Map<java.lang.String,java.lang.String> properties, java.lang.String prefix)
Load settings from aMap
instance.ConnectionFactory
load(java.util.Properties properties)
Load settings from aProperties
instance.ConnectionFactory
load(java.util.Properties properties, java.lang.String prefix)
Load settings from aProperties
instance.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, java.lang.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 theAddressResolver
.Connection
newConnection(java.lang.String connectionName)
Create a new broker connection.Connection
newConnection(java.util.concurrent.ExecutorService executor)
Create a new broker connection.Connection
newConnection(java.util.concurrent.ExecutorService executor, Address[] addrs)
Create a new broker connection, picking the first available address from the list.Connection
newConnection(java.util.concurrent.ExecutorService executor, Address[] addrs, java.lang.String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from the list.Connection
newConnection(java.util.concurrent.ExecutorService executor, AddressResolver addressResolver)
Create a new broker connection, picking the first available address from the list provided by theAddressResolver
.Connection
newConnection(java.util.concurrent.ExecutorService executor, AddressResolver addressResolver, java.lang.String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from the list provided by theAddressResolver
.Connection
newConnection(java.util.concurrent.ExecutorService executor, java.lang.String connectionName)
Create a new broker connection.Connection
newConnection(java.util.concurrent.ExecutorService executor, java.util.List<Address> addrs)
Create a new broker connection, picking the first available address from the list.Connection
newConnection(java.util.concurrent.ExecutorService executor, java.util.List<Address> addrs, java.lang.String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from the list.Connection
newConnection(java.util.List<Address> addrs)
Create a new broker connection, picking the first available address from the list.Connection
newConnection(java.util.List<Address> addrs, java.lang.String clientProvidedName)
Create a new broker connection with a client-provided name, picking the first available address from the list.ConnectionParams
params(java.util.concurrent.ExecutorService consumerWorkServiceExecutor)
static int
portOrDefault(int port, boolean ssl)
protected void
processUriQueryParameter(java.lang.String key, java.lang.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(java.util.Map<java.lang.String,java.lang.Object> clientProperties)
Replace the table of client properties that will be sent to the server during subsequent connection startups.void
setConnectionRecoveryTriggeringCondition(java.util.function.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 aCredentialsRefreshService
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(java.util.concurrent.ScheduledExecutorService executor)
Set the executor to use to send heartbeat frames.void
setHost(java.lang.String host)
void
setMaxInboundMessageBodySize(int maxInboundMessageBodySize)
Maximum body size of inbound (received) messages in bytes.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
setObservationCollector(ObservationCollector observationCollector)
Set observation collector.void
setPassword(java.lang.String password)
Set the password.void
setPort(int port)
Set the target port.private void
setQuery(java.lang.String rawQuery)
Convenience method for setting some fields from query parameters Will handle only a subset of the query parameters supported by the official erlang client https://www.rabbitmq.com/uri-query-parameters.htmlvoid
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 sizevoid
setRequestedHeartbeat(int requestedHeartbeat)
Set the requested heartbeat timeout.void
setSaslConfig(SaslConfig saslConfig)
Sets the sasl config to use when authenticatingvoid
setSharedExecutor(java.util.concurrent.ExecutorService executor)
Set the executor to use for consumer operation dispatch by default for newly created connections.void
setShutdownExecutor(java.util.concurrent.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(javax.net.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(java.util.concurrent.ThreadFactory threadFactory)
Set the thread factory used to instantiate new threads.void
setTopologyRecoveryEnabled(boolean topologyRecovery)
Enables or disables topology recoveryvoid
setTopologyRecoveryExecutor(java.util.concurrent.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 outboundCommand
s.void
setUri(java.lang.String uriString)
Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host.void
setUri(java.net.URI uri)
Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host.void
setUsername(java.lang.String username)
Set the user name.void
setVirtualHost(java.lang.String virtualHost)
Set the virtual host.void
setWorkPoolTimeout(int workPoolTimeout)
Timeout (in ms) for work pool enqueueing.private static java.lang.String
uriDecode(java.lang.String s)
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(java.lang.String protocol)
Convenience method for configuring TLS using the supplied protocol and a very trusting TrustManager.void
useSslProtocol(java.lang.String protocol, javax.net.ssl.TrustManager trustManager)
Convenience method for configuring TLS.void
useSslProtocol(javax.net.ssl.SSLContext context)
Sets up TLS with an initializedSSLContext
.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
MAX_UNSIGNED_SHORT
private static final int MAX_UNSIGNED_SHORT
- See Also:
- Constant Field Values
-
DEFAULT_USER
public static final java.lang.String DEFAULT_USER
Default user name- See Also:
- Constant Field Values
-
DEFAULT_PASS
public static final java.lang.String DEFAULT_PASS
Default password- See Also:
- Constant Field Values
-
DEFAULT_VHOST
public static final java.lang.String DEFAULT_VHOST
Default virtual host- See Also:
- Constant Field Values
-
DEFAULT_CHANNEL_MAX
public static final 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- See Also:
- Constant Field Values
-
DEFAULT_FRAME_MAX
public static final int DEFAULT_FRAME_MAX
Default maximum frame size; zero means no limit- See Also:
- Constant Field Values
-
DEFAULT_HEARTBEAT
public static final int DEFAULT_HEARTBEAT
Default heart-beat interval; 60 seconds- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final java.lang.String DEFAULT_HOST
The default host- See Also:
- Constant Field Values
-
USE_DEFAULT_PORT
public static final int USE_DEFAULT_PORT
'Use the default port' port- See Also:
- Constant Field Values
-
DEFAULT_AMQP_PORT
public static final int DEFAULT_AMQP_PORT
The default non-ssl port- See Also:
- Constant Field Values
-
DEFAULT_AMQP_OVER_SSL_PORT
public static final int DEFAULT_AMQP_OVER_SSL_PORT
The default ssl port- See Also:
- Constant Field Values
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT
The default TCP connection timeout: 60 seconds- See Also:
- Constant Field Values
-
DEFAULT_HANDSHAKE_TIMEOUT
public static final int DEFAULT_HANDSHAKE_TIMEOUT
The default AMQP 0-9-1 connection handshake timeout. See DEFAULT_CONNECTION_TIMEOUT for TCP (socket) connection timeout.- See Also:
- Constant Field Values
-
DEFAULT_SHUTDOWN_TIMEOUT
public static final int DEFAULT_SHUTDOWN_TIMEOUT
The default shutdown timeout; zero means wait indefinitely- See Also:
- Constant Field Values
-
DEFAULT_CHANNEL_RPC_TIMEOUT
public static final int DEFAULT_CHANNEL_RPC_TIMEOUT
The default continuation timeout for RPC calls in channels: 10 minutes
-
DEFAULT_NETWORK_RECOVERY_INTERVAL
public static final long DEFAULT_NETWORK_RECOVERY_INTERVAL
The default network recovery interval: 5000 millis- See Also:
- Constant Field Values
-
DEFAULT_WORK_POOL_TIMEOUT
public static final int DEFAULT_WORK_POOL_TIMEOUT
The default timeout for work pool enqueueing: no timeout- See Also:
- Constant Field Values
-
PREFERRED_TLS_PROTOCOL
private static final java.lang.String PREFERRED_TLS_PROTOCOL
- See Also:
- Constant Field Values
-
FALLBACK_TLS_PROTOCOL
private static final java.lang.String FALLBACK_TLS_PROTOCOL
- See Also:
- Constant Field Values
-
virtualHost
private java.lang.String virtualHost
-
host
private java.lang.String host
-
port
private int port
-
requestedChannelMax
private int requestedChannelMax
-
requestedFrameMax
private int requestedFrameMax
-
requestedHeartbeat
private int requestedHeartbeat
-
connectionTimeout
private int connectionTimeout
-
handshakeTimeout
private int handshakeTimeout
-
shutdownTimeout
private int shutdownTimeout
-
_clientProperties
private java.util.Map<java.lang.String,java.lang.Object> _clientProperties
-
socketFactory
private javax.net.SocketFactory socketFactory
-
saslConfig
private SaslConfig saslConfig
-
sharedExecutor
private java.util.concurrent.ExecutorService sharedExecutor
-
threadFactory
private java.util.concurrent.ThreadFactory threadFactory
-
shutdownExecutor
private java.util.concurrent.ExecutorService shutdownExecutor
-
heartbeatExecutor
private java.util.concurrent.ScheduledExecutorService heartbeatExecutor
-
socketConf
private SocketConfigurator socketConf
-
exceptionHandler
private ExceptionHandler exceptionHandler
-
credentialsProvider
private CredentialsProvider credentialsProvider
-
automaticRecovery
private boolean automaticRecovery
-
topologyRecovery
private boolean topologyRecovery
-
topologyRecoveryExecutor
private java.util.concurrent.ExecutorService topologyRecoveryExecutor
-
networkRecoveryInterval
private long networkRecoveryInterval
-
recoveryDelayHandler
private RecoveryDelayHandler recoveryDelayHandler
-
metricsCollector
private MetricsCollector metricsCollector
-
observationCollector
private ObservationCollector observationCollector
-
nio
private boolean nio
-
frameHandlerFactory
private FrameHandlerFactory frameHandlerFactory
-
nioParams
private NioParams nioParams
-
sslContextFactory
private SslContextFactory sslContextFactory
-
channelRpcTimeout
private int channelRpcTimeout
Continuation timeout on RPC calls.- Since:
- 4.1.0
-
channelShouldCheckRpcResponseType
private boolean channelShouldCheckRpcResponseType
Whether or not channels check the reply type of an RPC call. Default is false.- Since:
- 4.2.0
-
errorOnWriteListener
private ErrorOnWriteListener errorOnWriteListener
Listener called when a connection gets an IO error trying to write on the socket. Default listener triggers connection recovery asynchronously and propagates the exception.- Since:
- 4.5.0
-
workPoolTimeout
private int workPoolTimeout
Timeout in ms for work pool enqueuing.- Since:
- 4.5.0
-
topologyRecoveryFilter
private TopologyRecoveryFilter topologyRecoveryFilter
Filter to include/exclude entities from topology recovery.- Since:
- 4.8.0
-
connectionRecoveryTriggeringCondition
private java.util.function.Predicate<ShutdownSignalException> connectionRecoveryTriggeringCondition
Condition to trigger automatic connection recovery.- Since:
- 5.4.0
-
topologyRecoveryRetryHandler
private RetryHandler topologyRecoveryRetryHandler
Retry handler for topology recovery. Default is no retry.- Since:
- 5.4.0
-
recoveredQueueNameSupplier
private RecoveredQueueNameSupplier recoveredQueueNameSupplier
-
trafficListener
private TrafficListener trafficListener
Traffic listener notified of inbound and outboundCommand
s.Useful for debugging purposes. Default is no-op.
- Since:
- 5.5.0
-
credentialsRefreshService
private CredentialsRefreshService credentialsRefreshService
-
maxInboundMessageBodySize
private int maxInboundMessageBodySize
Maximum body size of inbound (received) messages in bytes.Default value is 67,108,864 (64 MiB).
-
URI_QUERY_PARAMETER_HANDLERS
private static final java.util.Map<java.lang.String,java.util.function.BiConsumer<java.lang.String,ConnectionFactory>> URI_QUERY_PARAMETER_HANDLERS
-
-
Method Detail
-
getHost
public java.lang.String getHost()
- Returns:
- the default host to use for connections
-
setHost
public void setHost(java.lang.String host)
- Parameters:
host
- the default host to use for connections
-
portOrDefault
public static int portOrDefault(int port, boolean ssl)
-
getPort
public int getPort()
- Returns:
- the default port to use for connections
-
setPort
public void setPort(int port)
Set the target port.- Parameters:
port
- the default port to use for connections
-
getUsername
public java.lang.String getUsername()
Retrieve the user name.- Returns:
- the AMQP user name to use when connecting to the broker
-
setUsername
public void setUsername(java.lang.String username)
Set the user name.- Parameters:
username
- the AMQP user name to use when connecting to the broker
-
getPassword
public java.lang.String getPassword()
Retrieve the password.- Returns:
- the password to use when connecting to the broker
-
setPassword
public void setPassword(java.lang.String password)
Set the password.- Parameters:
password
- the password to use when connecting to the broker
-
setCredentialsProvider
public void setCredentialsProvider(CredentialsProvider credentialsProvider)
Set a custom credentials provider. Default implementation uses static username and password.- Parameters:
credentialsProvider
- The custom implementation of CredentialsProvider to use when connecting to the broker.- Since:
- 4.5.0
- See Also:
DefaultCredentialsProvider
-
getVirtualHost
public java.lang.String getVirtualHost()
Retrieve the virtual host.- Returns:
- the virtual host to use when connecting to the broker
-
setVirtualHost
public void setVirtualHost(java.lang.String virtualHost)
Set the virtual host.- Parameters:
virtualHost
- the virtual host to use when connecting to the broker
-
setUri
public void setUri(java.net.URI uri) throws java.net.URISyntaxException, java.security.NoSuchAlgorithmException, java.security.KeyManagementException
Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host. If any part of the URI is omitted, the ConnectionFactory's corresponding variable is left unchanged.- Parameters:
uri
- is the AMQP URI containing the data- Throws:
java.net.URISyntaxException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
-
setUri
public void setUri(java.lang.String uriString) throws java.net.URISyntaxException, java.security.NoSuchAlgorithmException, java.security.KeyManagementException
Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host. If any part of the URI is omitted, the ConnectionFactory's corresponding variable is left unchanged. Note that not all valid AMQP URIs are accepted; in particular, the hostname must be given if the port, username or password are given, and escapes in the hostname are not permitted.- Parameters:
uriString
- is the AMQP URI containing the data- Throws:
java.net.URISyntaxException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
-
uriDecode
private static java.lang.String uriDecode(java.lang.String s)
-
setQuery
private void setQuery(java.lang.String rawQuery)
Convenience method for setting some fields from query parameters Will handle only a subset of the query parameters supported by the official erlang client https://www.rabbitmq.com/uri-query-parameters.html- Parameters:
rawQuery
- is the string containing the raw query parameters part from a URI
-
processUriQueryParameter
protected void processUriQueryParameter(java.lang.String key, java.lang.String value)
Hook to process query parameters not handled natively. Handled natively:heartbeat
,connection_timeout
,channel_max
.- Parameters:
key
-value
-
-
getRequestedChannelMax
public int getRequestedChannelMax()
Retrieve the requested maximum channel number- Returns:
- the initially requested maximum channel number; zero for unlimited
-
setRequestedChannelMax
public void setRequestedChannelMax(int requestedChannelMax)
Set the requested maximum channel number.Note the value must be between 0 and 65535 (unsigned short in AMQP 0-9-1).
- Parameters:
requestedChannelMax
- initially requested maximum channel number; zero for unlimited
-
getRequestedFrameMax
public int getRequestedFrameMax()
Retrieve the requested maximum frame size- Returns:
- the initially requested maximum frame size, in octets; zero for unlimited
-
setRequestedFrameMax
public void setRequestedFrameMax(int requestedFrameMax)
Set the requested maximum frame size- Parameters:
requestedFrameMax
- initially requested maximum frame size, in octets; zero for unlimited
-
getRequestedHeartbeat
public int getRequestedHeartbeat()
Retrieve the requested heartbeat interval.- Returns:
- the initially requested heartbeat interval, in seconds; zero for none
-
setConnectionTimeout
public void setConnectionTimeout(int timeout)
Set the TCP connection timeout.- Parameters:
timeout
- connection TCP establishment timeout in milliseconds; zero for infinite
-
getConnectionTimeout
public int getConnectionTimeout()
Retrieve the TCP connection timeout.- Returns:
- the TCP connection timeout, in milliseconds; zero for infinite
-
getHandshakeTimeout
public int getHandshakeTimeout()
Retrieve the AMQP 0-9-1 protocol handshake timeout.- Returns:
- the AMQP0-9-1 protocol handshake timeout, in milliseconds
-
setHandshakeTimeout
public void setHandshakeTimeout(int timeout)
Set the AMQP0-9-1 protocol handshake timeout.- Parameters:
timeout
- the AMQP0-9-1 protocol handshake timeout, in milliseconds
-
setShutdownTimeout
public void setShutdownTimeout(int shutdownTimeout)
Set the shutdown timeout. This is the amount of time that Consumer implementations have to continue working through deliveries (and other Consumer callbacks) after the connection has closed but before the ConsumerWorkService is torn down. If consumers exceed this timeout then any remaining queued deliveries (and other Consumer callbacks, including the Consumer's handleShutdownSignal() invocation) will be lost.- Parameters:
shutdownTimeout
- shutdown timeout in milliseconds; zero for infinite; default 10000
-
getShutdownTimeout
public int getShutdownTimeout()
Retrieve the shutdown timeout.- Returns:
- the shutdown timeout, in milliseconds; zero for infinite
-
setRequestedHeartbeat
public void setRequestedHeartbeat(int requestedHeartbeat)
Set the requested heartbeat timeout. Heartbeat frames will be sent at about 1/2 the timeout interval. If server heartbeat timeout is configured to a non-zero value, this method can only be used to lower the value; otherwise any value provided by the client will be used.Note the value must be between 0 and 65535 (unsigned short in AMQP 0-9-1).
- Parameters:
requestedHeartbeat
- the initially requested heartbeat timeout, in seconds; zero for none- See Also:
- RabbitMQ Heartbeats Guide
-
getClientProperties
public java.util.Map<java.lang.String,java.lang.Object> getClientProperties()
Retrieve the currently-configured table of client properties that will be sent to the server during connection startup. Clients may add, delete, and alter keys in this table. Such changes will take effect when the next new connection is started using this factory.- Returns:
- the map of client properties
- See Also:
setClientProperties(java.util.Map<java.lang.String, java.lang.Object>)
-
setClientProperties
public void setClientProperties(java.util.Map<java.lang.String,java.lang.Object> clientProperties)
Replace the table of client properties that will be sent to the server during subsequent connection startups.- Parameters:
clientProperties
- the map of extra client properties- See Also:
getClientProperties()
-
getSaslConfig
public SaslConfig getSaslConfig()
Gets the sasl config to use when authenticating- Returns:
- the sasl config
- See Also:
SaslConfig
-
setSaslConfig
public void setSaslConfig(SaslConfig saslConfig)
Sets the sasl config to use when authenticating- Parameters:
saslConfig
-- See Also:
SaslConfig
-
getSocketFactory
public javax.net.SocketFactory getSocketFactory()
Retrieve the socket factory used to make connections with.
-
setSocketFactory
public void setSocketFactory(javax.net.SocketFactory factory)
Set the socket factory used to create sockets for new connections. Can be used to customize TLS-related settings by passing in a javax.net.ssl.SSLSocketFactory instance. Note this applies only to blocking IO, not to NIO, as the NIO API doesn't use the SocketFactory API.- See Also:
useSslProtocol()
-
getSocketConfigurator
public SocketConfigurator getSocketConfigurator()
Get the socket configurator.
-
setSocketConfigurator
public void setSocketConfigurator(SocketConfigurator socketConfigurator)
Set the socket configurator. This gets a chance to "configure" a socket before it has been opened. The default socket configurator disables Nagle's algorithm.- Parameters:
socketConfigurator
- the configurator to use
-
setSharedExecutor
public void setSharedExecutor(java.util.concurrent.ExecutorService executor)
Set the executor to use for consumer operation dispatch by default for newly created connections. All connections that use this executor share it. It's developer's responsibility to shut down the executor when it is no longer needed.- Parameters:
executor
- executor service to be used for consumer operation
-
setShutdownExecutor
public void setShutdownExecutor(java.util.concurrent.ExecutorService executor)
Set the executor to use for connection shutdown. All connections that use this executor share it. It's developer's responsibility to shut down the executor when it is no longer needed.- Parameters:
executor
- executor service to be used for connection shutdown
-
setHeartbeatExecutor
public void setHeartbeatExecutor(java.util.concurrent.ScheduledExecutorService executor)
Set the executor to use to send heartbeat frames. All connections that use this executor share it. It's developer's responsibility to shut down the executor when it is no longer needed.- Parameters:
executor
- executor service to be used to send heartbeat
-
getThreadFactory
public java.util.concurrent.ThreadFactory getThreadFactory()
Retrieve the thread factory used to instantiate new threads.- See Also:
ThreadFactory
-
setThreadFactory
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Set the thread factory used to instantiate new threads.- See Also:
ThreadFactory
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
Get the exception handler.- See Also:
ExceptionHandler
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set the exception handler to use for newly created connections.- See Also:
ExceptionHandler
-
isSSL
public boolean isSSL()
-
useSslProtocol
public void useSslProtocol() throws java.security.NoSuchAlgorithmException, java.security.KeyManagementException
Convenience method for configuring TLS using the default set of TLS protocols and a trusting TrustManager. This setup is only suitable for development and QA environments. The trust manager will trust every server certificate presented to it, this is convenient for local development but not recommended to use in production as it provides no protection against man-in-the-middle attacks. PreferuseSslProtocol(SSLContext)
.- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
-
useSslProtocol
public void useSslProtocol(java.lang.String protocol) throws java.security.NoSuchAlgorithmException, java.security.KeyManagementException
Convenience method for configuring TLS using the supplied protocol and a very trusting TrustManager. This setup is only suitable for development and QA environments. The trust manager will trust every server certificate presented to it, this is convenient for local development but not recommended to use in production as it provides no protection against man-in-the-middle attacks. UseuseSslProtocol(SSLContext)
in production environments. The producedSSLContext
instance will be shared by all the connections created by this connection factory. UsesetSslContextFactory(SslContextFactory)
for more flexibility.- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
- See Also:
setSslContextFactory(SslContextFactory)
-
useSslProtocol
public void useSslProtocol(java.lang.String protocol, javax.net.ssl.TrustManager trustManager) throws java.security.NoSuchAlgorithmException, java.security.KeyManagementException
Convenience method for configuring TLS. Pass in the TLS protocol version to use, e.g. "TLSv1.2" or "TLSv1.1", and a desiredTrustManager
. The producedSSLContext
instance will be shared with all the connections created by this connection factory. UsesetSslContextFactory(SslContextFactory)
for more flexibility.- Parameters:
protocol
- the TLS protocol to use.trustManager
- theTrustManager
implementation to use.- Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
- See Also:
setSslContextFactory(SslContextFactory)
,useSslProtocol(SSLContext)
-
useSslProtocol
public void useSslProtocol(javax.net.ssl.SSLContext context)
Sets up TLS with an initializedSSLContext
. The caller is responsible for setting up the context with aTrustManager
with suitable security guarantees, e.g. peer verification. TheSSLContext
instance will be shared with all the connections created by this connection factory. UsesetSslContextFactory(SslContextFactory)
for more flexibility.- Parameters:
context
- An initialized SSLContext- See Also:
setSslContextFactory(SslContextFactory)
-
enableHostnameVerification
public void enableHostnameVerification()
Enable server hostname verification for TLS connections.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 theuseSslProtocol
methods.- Since:
- 5.4.0
- See Also:
NioParams.enableHostnameVerification()
,NioParams.setSslEngineConfigurator(SslEngineConfigurator)
,SslEngineConfigurators.ENABLE_HOSTNAME_VERIFICATION
,SocketConfigurators.ENABLE_HOSTNAME_VERIFICATION
,useSslProtocol(String)
,useSslProtocol(SSLContext)
,useSslProtocol()
,useSslProtocol(String, TrustManager)
-
enableHostnameVerificationForNio
protected void enableHostnameVerificationForNio()
-
enableHostnameVerificationForBlockingIo
protected void enableHostnameVerificationForBlockingIo()
-
computeDefaultTlsProtocol
public static java.lang.String computeDefaultTlsProtocol(java.lang.String[] supportedProtocols)
-
isAutomaticRecoveryEnabled
public boolean isAutomaticRecoveryEnabled()
Returns true if automatic connection recovery is enabled, false otherwise- Returns:
- true if automatic connection recovery is enabled, false otherwise
- See Also:
- Automatic Recovery
-
setAutomaticRecoveryEnabled
public void setAutomaticRecoveryEnabled(boolean automaticRecovery)
Enables or disables automatic connection recovery.- Parameters:
automaticRecovery
- if true, enables connection recovery- See Also:
- Automatic Recovery
-
isTopologyRecoveryEnabled
public boolean isTopologyRecoveryEnabled()
Returns true if topology recovery is enabled, false otherwise- Returns:
- true if topology recovery is enabled, false otherwise
- See Also:
- Automatic Recovery
-
setTopologyRecoveryEnabled
public void setTopologyRecoveryEnabled(boolean topologyRecovery)
Enables or disables topology recovery- Parameters:
topologyRecovery
- if true, enables topology recovery- See Also:
- Automatic Recovery
-
getTopologyRecoveryExecutor
public java.util.concurrent.ExecutorService getTopologyRecoveryExecutor()
Get the executor to use for parallel topology recovery. If null (the default), recovery is done single threaded on the main connection thread.- Returns:
- thread pool executor
- Since:
- 4.7.0
-
setTopologyRecoveryExecutor
public void setTopologyRecoveryExecutor(java.util.concurrent.ExecutorService topologyRecoveryExecutor)
Set the executor to use for parallel topology recovery. If null (the default), recovery is done single threaded on the main connection thread. It is recommended to pass a ThreadPoolExecutor that will allow its core threads to timeout so these threads can die when recovery is complete. It's developer's responsibility to shut down the executor when it is no longer needed. Note: yourExceptionHandler.handleTopologyRecoveryException(Connection, Channel, TopologyRecoveryException)
method should be thread-safe.- Parameters:
topologyRecoveryExecutor
- thread pool executor- Since:
- 4.7.0
-
setMetricsCollector
public void setMetricsCollector(MetricsCollector metricsCollector)
-
getMetricsCollector
public MetricsCollector getMetricsCollector()
-
setObservationCollector
public void setObservationCollector(ObservationCollector observationCollector)
Set observation collector.- Parameters:
observationCollector
- the collector instance- Since:
- 5.19.0
- See Also:
ObservationCollector
,com.rabbitmq.client.observation.micrometer.MicrometerObservationCollectorBuilder
-
setCredentialsRefreshService
public void setCredentialsRefreshService(CredentialsRefreshService credentialsRefreshService)
Set aCredentialsRefreshService
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 andudpate.secret
frame sending, based on the information provided by theCredentialsProvider
.Note the
CredentialsRefreshService
is used only when theCredentialsProvider
signals credentials can expire, by returning a non-null value fromCredentialsProvider.getTimeBeforeExpiration()
.- Parameters:
credentialsRefreshService
- the refresh service to use- See Also:
setCredentialsProvider(CredentialsProvider)
,DefaultCredentialsRefreshService
-
createFrameHandlerFactory
protected FrameHandlerFactory createFrameHandlerFactory() throws java.io.IOException
- Throws:
java.io.IOException
-
newConnection
public Connection newConnection(Address[] addrs) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
addrs
- an array of known broker addresses (hostname/port pairs) to try in order- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(AddressResolver addressResolver) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list provided by theAddressResolver
. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address provided by theAddressResolver
.- Parameters:
addressResolver
- discovery service to list potential addresses (hostname/port pairs) to connect to- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(Address[] addrs, java.lang.String clientProvidedName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection with a client-provided name, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.util.List<Address> addrs) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
addrs
- a List of known broker addresses (hostname/port pairs) to try in order- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.util.List<Address> addrs, java.lang.String clientProvidedName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection with a client-provided name, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, Address[] addrs) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
executor
- thread execution service for consumers on the connectionaddrs
- an array of known broker addresses (hostname/port pairs) to try in order- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, Address[] addrs, java.lang.String clientProvidedName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection with a client-provided name, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, java.util.List<Address> addrs) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
executor
- thread execution service for consumers on the connectionaddrs
- a List of known broker addrs (hostname/port pairs) to try in order- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, AddressResolver addressResolver) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection, picking the first available address from the list provided by theAddressResolver
. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address provided by theAddressResolver
.- Parameters:
executor
- thread execution service for consumers on the connectionaddressResolver
- discovery service to list potential addresses (hostname/port pairs) to connect to- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, java.util.List<Address> addrs, java.lang.String clientProvidedName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection with a client-provided name, picking the first available address from the list. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address from the provided list.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, AddressResolver addressResolver, java.lang.String clientProvidedName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection with a client-provided name, picking the first available address from the list provided by theAddressResolver
. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Future reconnection attempts will pick a random accessible address provided by theAddressResolver
.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
- See Also:
- Automatic Recovery
-
params
public ConnectionParams params(java.util.concurrent.ExecutorService consumerWorkServiceExecutor)
-
createConnection
protected AMQConnection createConnection(ConnectionParams params, FrameHandler frameHandler, MetricsCollector metricsCollector)
-
newConnection
public Connection newConnection() throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Reconnection attempts will always use the address configured onConnectionFactory
.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.lang.String connectionName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Reconnection attempts will always use the address configured onConnectionFactory
.- Parameters:
connectionName
- client-provided connection name (an arbitrary string). Will be displayed in management UI if the server supports it.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Reconnection attempts will always use the address configured onConnectionFactory
.- Parameters:
executor
- thread execution service for consumers on the connection- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
newConnection
public Connection newConnection(java.util.concurrent.ExecutorService executor, java.lang.String connectionName) throws java.io.IOException, java.util.concurrent.TimeoutException
Create a new broker connection. If automatic connection recovery is enabled, the connection returned by this method will beRecoverable
. Reconnection attempts will always use the address configured onConnectionFactory
.- Parameters:
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.- Returns:
- an interface to the connection
- Throws:
java.io.IOException
- if it encounters a problemjava.util.concurrent.TimeoutException
-
createAddressResolver
protected AddressResolver createAddressResolver(java.util.List<Address> addresses)
-
clone
public ConnectionFactory clone()
- Overrides:
clone
in classjava.lang.Object
-
load
public ConnectionFactory load(java.lang.String propertyFileLocation) throws java.io.IOException
Load settings from a property file. Keys must be prefixed withrabbitmq.
, useload(String, String)
to specify your own prefix.- Parameters:
propertyFileLocation
- location of the property file to use- Throws:
java.io.IOException
- when something goes wrong reading the file- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
load
public ConnectionFactory load(java.lang.String propertyFileLocation, java.lang.String prefix) throws java.io.IOException
Load settings from a property file.- Parameters:
propertyFileLocation
- location of the property file to useprefix
- key prefix for the entries in the file- Throws:
java.io.IOException
- when something goes wrong reading the file- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
load
public ConnectionFactory load(java.util.Properties properties)
Load settings from aProperties
instance. Keys must be prefixed withrabbitmq.
, useload(Properties, String)
to specify your own prefix.- Parameters:
properties
- source for settings- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
load
public ConnectionFactory load(java.util.Properties properties, java.lang.String prefix)
Load settings from aProperties
instance.- Parameters:
properties
- source for settingsprefix
- key prefix for properties entries- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
load
public ConnectionFactory load(java.util.Map<java.lang.String,java.lang.String> properties)
Load settings from aMap
instance. Keys must be prefixed withrabbitmq.
, useload(Map, String)
to specify your own prefix.- Parameters:
properties
- source for settings- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
load
public ConnectionFactory load(java.util.Map<java.lang.String,java.lang.String> properties, java.lang.String prefix)
Load settings from aMap
instance.- Parameters:
properties
- source for settingsprefix
- key prefix for map entries- Since:
- 4.4.0
- See Also:
ConnectionFactoryConfigurator
-
getNetworkRecoveryInterval
public long getNetworkRecoveryInterval()
Returns automatic connection recovery interval in milliseconds.- Returns:
- how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
-
setNetworkRecoveryInterval
public void setNetworkRecoveryInterval(int networkRecoveryInterval)
Sets connection recovery interval. Default is 5000. UsesRecoveryDelayHandler.DefaultRecoveryDelayHandler
by default. Use anotherRecoveryDelayHandler
implementation for more flexibility.- Parameters:
networkRecoveryInterval
- how long will automatic recovery wait before attempting to reconnect, in ms- See Also:
RecoveryDelayHandler
-
setNetworkRecoveryInterval
public void setNetworkRecoveryInterval(long networkRecoveryInterval)
Sets connection recovery interval. Default is 5000. UsesRecoveryDelayHandler.DefaultRecoveryDelayHandler
by default. Use anotherRecoveryDelayHandler
implementation for more flexibility.- Parameters:
networkRecoveryInterval
- how long will automatic recovery wait before attempting to reconnect, in ms- See Also:
RecoveryDelayHandler
-
getRecoveryDelayHandler
public RecoveryDelayHandler getRecoveryDelayHandler()
Returns automatic connection recovery delay handler.- Returns:
- recovery delay handler. May be null if not set.
- Since:
- 4.3.0
-
setRecoveryDelayHandler
public void setRecoveryDelayHandler(RecoveryDelayHandler recoveryDelayHandler)
Sets the automatic connection recovery delay handler.- Parameters:
recoveryDelayHandler
- the recovery delay handler- Since:
- 4.3.0
-
setNioParams
public void setNioParams(NioParams nioParams)
Sets the parameters when using NIO.- Parameters:
nioParams
-- See Also:
NioParams
-
getNioParams
public NioParams getNioParams()
Retrieve the parameters for NIO mode.- Returns:
-
useNio
public void useNio()
Use non-blocking IO (NIO) for communication with the server. With NIO, several connections created from the sameConnectionFactory
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. UseNioParams
to tune NIO and aSocketChannelConfigurator
to configure the underlyingSocketChannel
s for connections.- See Also:
NioParams
,SocketChannelConfigurator
,SocketChannel
,Selector
-
useBlockingIo
public void useBlockingIo()
Use blocking IO for communication with the server. With blocking IO, each connection creates its own thread to read data from the server.
-
setChannelRpcTimeout
public void setChannelRpcTimeout(int channelRpcTimeout)
Set the continuation timeout for RPC calls in channels. Default is 10 minutes. 0 means no timeout.- Parameters:
channelRpcTimeout
-
-
getChannelRpcTimeout
public int getChannelRpcTimeout()
Get the timeout for RPC calls in channels.- Returns:
-
setMaxInboundMessageBodySize
public void setMaxInboundMessageBodySize(int maxInboundMessageBodySize)
Maximum body size of inbound (received) messages in bytes.Default value is 67,108,864 (64 MiB).
- Parameters:
maxInboundMessageBodySize
- the maximum size of inbound messages
-
setSslContextFactory
public void setSslContextFactory(SslContextFactory sslContextFactory)
The factory to create SSL contexts. This provides more flexibility to createSSLContext
s for different connections than sharing theSSLContext
with all the connections produced by the connection factory (which is the case with theuseSslProtocol()
methods). This way, different connections with a different certificate for each of them is a possible scenario.- Parameters:
sslContextFactory
-- Since:
- 5.0.0
- See Also:
useSslProtocol(SSLContext)
-
setChannelShouldCheckRpcResponseType
public void setChannelShouldCheckRpcResponseType(boolean channelShouldCheckRpcResponseType)
When set to true, channels will check the response type (e.g. queue.declare expects a queue.declare-ok response) of RPC calls and ignore those that do not match. Default is false.- Parameters:
channelShouldCheckRpcResponseType
-
-
isChannelShouldCheckRpcResponseType
public boolean isChannelShouldCheckRpcResponseType()
-
setWorkPoolTimeout
public void setWorkPoolTimeout(int workPoolTimeout)
Timeout (in ms) for work pool enqueueing. TheWorkPool
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.- Parameters:
workPoolTimeout
- timeout in ms- Since:
- 4.5.0
-
getWorkPoolTimeout
public int getWorkPoolTimeout()
-
setErrorOnWriteListener
public void setErrorOnWriteListener(ErrorOnWriteListener errorOnWriteListener)
Set a listener to be called when connection gets an IO error trying to write on the socket. Default listener triggers connection recovery asynchronously and propagates the exception. Override the default listener to disable or customise automatic connection triggering on write operations.- Parameters:
errorOnWriteListener
- the listener- Since:
- 4.5.0
-
setTopologyRecoveryFilter
public void setTopologyRecoveryFilter(TopologyRecoveryFilter topologyRecoveryFilter)
Set filter to include/exclude entities from topology recovery.- Since:
- 4.8.0
-
setConnectionRecoveryTriggeringCondition
public void setConnectionRecoveryTriggeringCondition(java.util.function.Predicate<ShutdownSignalException> connectionRecoveryTriggeringCondition)
Allows to decide on automatic connection recovery is triggered. Default is for shutdown not initiated by application or missed heartbeat errors.- Parameters:
connectionRecoveryTriggeringCondition
-
-
setTopologyRecoveryRetryHandler
public void setTopologyRecoveryRetryHandler(RetryHandler topologyRecoveryRetryHandler)
Set retry handler for topology recovery. Default is no retry.- Parameters:
topologyRecoveryRetryHandler
-- Since:
- 5.4.0
-
setRecoveredQueueNameSupplier
public void setRecoveredQueueNameSupplier(RecoveredQueueNameSupplier recoveredQueueNameSupplier)
Set the recovered queue name supplier. Default is use the same queue name when recovering queues.- Parameters:
recoveredQueueNameSupplier
- queue name supplier
-
setTrafficListener
public void setTrafficListener(TrafficListener trafficListener)
Traffic listener notified of inbound and outboundCommand
s.Useful for debugging purposes, e.g. logging all sent and received messages. Default is no-op.
- Parameters:
trafficListener
-- Since:
- 5.5.0
- See Also:
TrafficListener
,LogTrafficListener
-
ensureUnsignedShort
public static int ensureUnsignedShort(int value)
-
-