com.rabbitmq.client
Class ConnectionFactory

java.lang.Object
  extended by com.rabbitmq.client.ConnectionFactory

public class ConnectionFactory
extends java.lang.Object

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


Field Summary
static java.lang.String DEFAULT_SSL_PROTOCOL
          The default SSL protocol (currently "SSLv3").
 
Constructor Summary
ConnectionFactory()
          Instantiate a ConnectionFactory with a default set of parameters.
ConnectionFactory(ConnectionParameters params)
          Instantiate a ConnectionFactory with the given connection parameters.
 
Method Summary
protected  void configureSocket(java.net.Socket socket)
          Provides a hook to insert custom configuration of the sockets used to connect to an AMQP server before they connect.
protected  FrameHandler createFrameHandler(Address addr)
           
 ConnectionParameters getParameters()
          Retrieve the connection parameters.
 javax.net.SocketFactory getSocketFactory()
          Retrieve the socket factory used to make connections with.
 Connection newConnection(Address[] addrs)
          Create a new broker connection (no redirects allowed)
 Connection newConnection(Address[] addrs, int maxRedirects)
          Create a new broker connection
 Connection newConnection(java.lang.String hostName)
          Create a new broker connection, using the default AMQP port
 Connection newConnection(java.lang.String hostName, int portNumber)
          Instantiates a connection and return an interface to it.
 void setSocketFactory(javax.net.SocketFactory factory)
          Set the socket factory used to make connections with.
 void useSslProtocol()
          Convenience method for setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.
 void useSslProtocol(javax.net.ssl.SSLContext context)
          Convenience method for setting up an SSL socket factory.
 void useSslProtocol(java.lang.String protocol)
          Convenience method for setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.
 void useSslProtocol(java.lang.String protocol, javax.net.ssl.TrustManager trustManager)
          Convenience method for setting up an SSL socket factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SSL_PROTOCOL

public static final java.lang.String DEFAULT_SSL_PROTOCOL
The default SSL protocol (currently "SSLv3").

See Also:
Constant Field Values
Constructor Detail

ConnectionFactory

public ConnectionFactory()
Instantiate a ConnectionFactory with a default set of parameters.


ConnectionFactory

public ConnectionFactory(ConnectionParameters params)
Instantiate a ConnectionFactory with the given connection parameters.

Parameters:
params - the relevant parameters for instantiating the broker connection
Method Detail

getParameters

public ConnectionParameters getParameters()
Retrieve the connection parameters.

Returns:
the initialization parameters used to open the connection

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 make connections with. Can be used to enable SSL connections by passing in a javax.net.ssl.SSLSocketFactory instance.

See Also:
useSslProtocol()

useSslProtocol

public void useSslProtocol()
                    throws java.security.NoSuchAlgorithmException,
                           java.security.KeyManagementException
Convenience method for setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.

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 setting up a SSL socket factory, using the DEFAULT_SSL_PROTOCOL and a trusting TrustManager.

Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException

useSslProtocol

public void useSslProtocol(java.lang.String protocol,
                           javax.net.ssl.TrustManager trustManager)
                    throws java.security.NoSuchAlgorithmException,
                           java.security.KeyManagementException
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.
Throws:
java.security.NoSuchAlgorithmException
java.security.KeyManagementException

useSslProtocol

public void useSslProtocol(javax.net.ssl.SSLContext context)
Convenience method for setting up an SSL socket factory. Pass in an initialized SSLContext.

Parameters:
context - An initialized SSLContext

createFrameHandler

protected FrameHandler createFrameHandler(Address addr)
                                   throws java.io.IOException
Throws:
java.io.IOException

configureSocket

protected void configureSocket(java.net.Socket socket)
                        throws java.io.IOException
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:
java.io.IOException

newConnection

public Connection newConnection(Address[] addrs,
                                int maxRedirects)
                         throws java.io.IOException
Create a new broker connection

Parameters:
addrs - an array of known broker addresses (hostname/port pairs) to try in order
maxRedirects - the maximum allowable number of redirects
Returns:
an interface to the connection
Throws:
java.io.IOException - if it encounters a problem

newConnection

public Connection newConnection(Address[] addrs)
                         throws java.io.IOException
Create a new broker connection (no redirects allowed)

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 problem

newConnection

public Connection newConnection(java.lang.String hostName,
                                int portNumber)
                         throws java.io.IOException
Instantiates a connection and return an interface to it.

Parameters:
hostName - the host to connect to
portNumber - the port number to use
Returns:
an interface to the connection
Throws:
java.io.IOException - if it encounters a problem

newConnection

public Connection newConnection(java.lang.String hostName)
                         throws java.io.IOException
Create a new broker connection, using the default AMQP port

Parameters:
hostName - the host to connect to
Returns:
an interface to the connection
Throws:
java.io.IOException - if it encounters a problem