public class

ConnectionFactory

extends Object
implements Cloneable
java.lang.Object
   ↳ com.rabbitmq.client.ConnectionFactory

Class Overview

Convenience "factory" class to facilitate opening a Connection to an AMQP broker.

Summary

Constants
int DEFAULT_AMQP_OVER_SSL_PORT The default ssl port
int DEFAULT_CHANNEL_MAX Default maximum channel number; zero for unlimited
int DEFAULT_CONNECTION_TIMEOUT The default connection timeout; zero means wait indefinitely
int DEFAULT_FRAME_MAX Default maximum frame size; zero means no limit
int DEFAULT_HEARTBEAT Default heart-beat interval; zero means no heart-beats
String DEFAULT_HOST The default host
int DEFAULT_NUM_CONSUMER_THREADS Default Executor threads
String DEFAULT_PASS Default password
String DEFAULT_USER Default user name
String DEFAULT_VHOST Default virtual host
int USE_DEFAULT_PORT 'Use the default port' port
Fields
public static final int DEFAULT_AMQP_PORT The default non-ssl port
Public Constructors
ConnectionFactory()
Public Methods
ConnectionFactory clone()
Map<StringObject> getClientProperties()
Retrieve the currently-configured table of client properties that will be sent to the server during connection startup.
int getConnectionTimeout()
Retrieve the connection timeout.
String getHost()
int getNumConsumerThreads()
String getPassword()
Retrieve the password.
int getPort()
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@return
SocketFactory getSocketFactory()
Retrieve the socket factory used to make connections with.
String getUsername()
Retrieve the user name.
String getVirtualHost()
Retrieve the virtual host.
boolean isSSL()
Connection newConnection(Address[] addrs)
Create a new broker connection
Connection newConnection(ExecutorService executor)
Create a new broker connection
Connection newConnection(ExecutorService executor, Address[] addrs)
Create a new broker connection
Connection newConnection()
Create a new broker connection
void setClientProperties(Map<StringObject> clientProperties)
Replace the table of client properties that will be sent to the server during subsequent connection startups.
void setConnectionTimeout(int connectionTimeout)
Set the connection timeout.
void setHost(String host)
void setNumConsumerThreads(int numConsumerThreads)
void setPassword(String password)
Set the password.
void setPort(int port)
Set the target port.
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.
void setSaslConfig(SaslConfig saslConfig)
Sets the sasl config to use when authenticating
void setSocketFactory(SocketFactory factory)
Set the socket factory used to make connections with.
void setUri(URI uri)
Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host.
void setUri(String uriString)
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 useSslProtocol(SSLContext context)
Convenience method for setting up an SSL socket factory.
void useSslProtocol(String protocol)
Convenience method for setting up a SSL socket factory, using the supplied protocol and a very trusting TrustManager.
void useSslProtocol(String protocol, TrustManager trustManager)
Convenience method for setting up an SSL socket factory.
void useSslProtocol()
Convenience method for setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.
Protected Methods
void configureSocket(Socket socket)
Provides a hook to insert custom configuration of the sockets used to connect to an AMQP server before they connect.
FrameHandler createFrameHandler(Address addr)
FrameHandler createFrameHandler(Socket sock)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEFAULT_AMQP_OVER_SSL_PORT

The default ssl port

Constant Value: 5671 (0x00001627)

public static final int DEFAULT_CHANNEL_MAX

Default maximum channel number; zero for unlimited

Constant Value: 0 (0x00000000)

public static final int DEFAULT_CONNECTION_TIMEOUT

The default connection timeout; zero means wait indefinitely

Constant Value: 0 (0x00000000)

public static final int DEFAULT_FRAME_MAX

Default maximum frame size; zero means no limit

Constant Value: 0 (0x00000000)

public static final int DEFAULT_HEARTBEAT

Default heart-beat interval; zero means no heart-beats

Constant Value: 0 (0x00000000)

public static final String DEFAULT_HOST

The default host

Constant Value: "localhost"

public static final int DEFAULT_NUM_CONSUMER_THREADS

Default Executor threads

Constant Value: 5 (0x00000005)

public static final String DEFAULT_PASS

Default password

Constant Value: "guest"

public static final String DEFAULT_USER

Default user name

Constant Value: "guest"

public static final String DEFAULT_VHOST

Default virtual host

Constant Value: "/"

public static final int USE_DEFAULT_PORT

'Use the default port' port

Constant Value: -1 (0xffffffff)

Fields

public static final int DEFAULT_AMQP_PORT

The default non-ssl port

Public Constructors

public ConnectionFactory ()

Public Methods

public ConnectionFactory clone ()

public Map<StringObject> 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

public int getConnectionTimeout ()

Retrieve the connection timeout.

Returns
  • the connection timeout, in milliseconds; zero for infinite

public String getHost ()

Returns
  • the default host to use for connections

public int getNumConsumerThreads ()

Returns
  • number of consumer threads in default ExecutorService

public String getPassword ()

Retrieve the password.

Returns
  • the password to use when connecting to the broker

public int getPort ()

Returns
  • the default port to use for connections

public int getRequestedChannelMax ()

Retrieve the requested maximum channel number

Returns
  • the initially requested maximum channel number; zero for unlimited

public int getRequestedFrameMax ()

Retrieve the requested maximum frame size

Returns
  • the initially requested maximum frame size, in octets; zero for unlimited

public int getRequestedHeartbeat ()

Retrieve the requested heartbeat interval.

Returns
  • the initially requested heartbeat interval, in seconds; zero for none

public SaslConfig getSaslConfig ()

Gets the sasl config to use when authenticating@return

See Also

public SocketFactory getSocketFactory ()

Retrieve the socket factory used to make connections with.

public String getUsername ()

Retrieve the user name.

Returns
  • the AMQP user name to use when connecting to the broker

public String getVirtualHost ()

Retrieve the virtual host.

Returns
  • the virtual host to use when connecting to the broker

public boolean isSSL ()

public Connection newConnection (Address[] addrs)

Create a new broker connection

Parameters
addrs an array of known broker addresses (hostname/port pairs) to try in order
Returns
  • an interface to the connection
Throws
IOException if it encounters a problem

public Connection newConnection (ExecutorService executor)

Create a new broker connection

Parameters
executor thread execution service for consumers on the connection
Returns
  • an interface to the connection
Throws
IOException if it encounters a problem

public Connection newConnection (ExecutorService executor, Address[] addrs)

Create a new broker connection

Parameters
executor thread execution service for consumers on the connection
addrs an array of known broker addresses (hostname/port pairs) to try in order
Returns
  • an interface to the connection
Throws
IOException if it encounters a problem

public Connection newConnection ()

Create a new broker connection

Returns
  • an interface to the connection
Throws
IOException if it encounters a problem

public void setClientProperties (Map<StringObject> 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

public void setConnectionTimeout (int connectionTimeout)

Set the connection timeout.

Parameters
connectionTimeout connection establishment timeout in milliseconds; zero for infinite

public void setHost (String host)

Parameters
host the default host to use for connections

public void setNumConsumerThreads (int numConsumerThreads)

Parameters
numConsumerThreads threads in created private executor service

public void setPassword (String password)

Set the password.

Parameters
password the password to use when connecting to the broker

public void setPort (int port)

Set the target port.

Parameters
port the default port to use for connections

public void setRequestedChannelMax (int requestedChannelMax)

Set the requested maximum channel number

Parameters
requestedChannelMax initially requested maximum channel number; zero for unlimited

public void setRequestedFrameMax (int requestedFrameMax)

Set the requested maximum frame size

Parameters
requestedFrameMax initially requested maximum frame size, in octets; zero for unlimited

public void setRequestedHeartbeat (int requestedHeartbeat)

Set the requested heartbeat.

Parameters
requestedHeartbeat the initially requested heartbeat interval, in seconds; zero for none

public void setSaslConfig (SaslConfig saslConfig)

Sets the sasl config to use when authenticating

See Also

public void setSocketFactory (SocketFactory factory)

Set the socket factory used to make connections with. Can be used to enable SSL connections by passing in a javax.net.ssl.SSLSocketFactory instance.

See Also

public void setUri (URI uri)

Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host. If any part of the URI is ommited, the ConnectionFactory's corresponding variable is left unchanged.

Parameters
uri is the AMQP URI containing the data

public void setUri (String uriString)

Convenience method for setting the fields in an AMQP URI: host, port, username, password and virtual host. If any part of the URI is ommited, 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

public void setUsername (String username)

Set the user name.

Parameters
username the AMQP user name to use when connecting to the broker

public void setVirtualHost (String virtualHost)

Set the virtual host.

Parameters
virtualHost the virtual host to use when connecting to the broker

public void useSslProtocol (SSLContext context)

Convenience method for setting up an SSL socket factory. Pass in an initialized SSLContext.

Parameters
context An initialized SSLContext

public void useSslProtocol (String protocol)

Convenience method for setting up a SSL socket factory, using the supplied protocol and a very trusting TrustManager.

public void useSslProtocol (String protocol, TrustManager trustManager)

Convenience method for setting up an SSL socket factory. Pass in the SSL protocol to use, e.g. "TLS" or "SSLv3".

Parameters
protocol SSL protocol to use.

public void useSslProtocol ()

Convenience method for setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.

Protected Methods

protected void configureSocket (Socket socket)

Provides a hook to insert custom configuration of the sockets used to connect to an AMQP server before they connect. The default behaviour of this method is to disable Nagle's algorithm to get more consistently low latency. However it may be overridden freely and there is no requirement to retain this behaviour.

Parameters
socket The socket that is to be used for the Connection
Throws
IOException

protected FrameHandler createFrameHandler (Address addr)

Throws
IOException

protected FrameHandler createFrameHandler (Socket sock)

Throws
IOException