com.rabbitmq.client
Interface Connection

All Superinterfaces:
ShutdownNotifier
All Known Implementing Classes:
AMQConnection

public interface Connection
extends ShutdownNotifier

Public API: Interface to an AMQ connection. See the see the spec for details.

To connect to a broker, fill in a ConnectionParameters and use a ConnectionFactory as follows:

 ConnectionParameters params = new ConnectionParameters();
 params.setUsername(userName);
 params.setPassword(password);
 params.setVirtualHost(virtualHost);
 params.setRequestedHeartbeat(0);
 ConnectionFactory factory = new ConnectionFactory(params);
 Connection conn = factory.newConnection(hostName, AMQP.PROTOCOL.PORT);

 // Then open a channel and retrieve an access ticket:

 Channel channel = conn.createChannel();
 int ticket = channel.accessRequest(realmName);
 
Current implementations are thread-safe for code at the client API level, and in fact thread-safe internally except for code within RPC calls.


Method Summary
 void abort()
          Abort this connection and all its channels.
 void abort(int timeout)
          Abort this connection and all its channels.
 void close()
          Close this connection and all its channels.
 void close(int timeout)
          Close this connection and all its channels This method will wait with the given timeout for all the close operations to complete.
 Channel createChannel()
          Create a new channel, using an internally allocated channel number.
 Channel createChannel(int channelNumber)
          Create a new channel, using the specified channel number if possible.
 int getChannelMax()
          Get the negotiated maximum number of channels allowed.
 int getFrameMax()
          Get the negotiated maximum frame size.
 int getHeartbeat()
          Get the negotiated heartbeat interval.
 java.lang.String getHost()
          Retrieve the host.
 Address[] getKnownHosts()
          Retrieve the known hosts.
 ConnectionParameters getParameters()
          Retrieve the connection parameters.
 int getPort()
          Retrieve the port number.
 
Methods inherited from interface com.rabbitmq.client.ShutdownNotifier
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener
 

Method Detail

getHost

java.lang.String getHost()
Retrieve the host.

Returns:
the hostname of the peer we're connected to.

getPort

int getPort()
Retrieve the port number.

Returns:
the port number of the peer we're connected to.

getParameters

ConnectionParameters getParameters()
Retrieve the connection parameters.

Returns:
the initialization parameters used to open this connection.

getChannelMax

int getChannelMax()
Get the negotiated maximum number of channels allowed. Note that this is the current setting, as opposed to the initially-requested setting available from getParameters().ConnectionParameters.getRequestedChannelMax().

Returns:
the maximum number of simultaneously-open channels permitted for this connection.

getFrameMax

int getFrameMax()
Get the negotiated maximum frame size. Note that this is the current setting, as opposed to the initially-requested setting available from getParameters().ConnectionParameters.getRequestedFrameMax().

Returns:
the maximum frame size, in octets; zero if unlimited

getHeartbeat

int getHeartbeat()
Get the negotiated heartbeat interval. Note that this is the current setting, as opposed to the initially-requested setting available from getParameters().ConnectionParameters.getRequestedHeartbeat().

Returns:
the heartbeat interval, in seconds; zero if none

getKnownHosts

Address[] getKnownHosts()
Retrieve the known hosts.

Returns:
an array of addresses for all hosts that came back in the initial AMQP.Connection.OpenOk open-ok method

createChannel

Channel createChannel()
                      throws java.io.IOException
Create a new channel, using an internally allocated channel number.

Returns:
a new channel descriptor, or null if none is available
Throws:
java.io.IOException - if an I/O problem is encountered

createChannel

Channel createChannel(int channelNumber)
                      throws java.io.IOException
Create a new channel, using the specified channel number if possible.

Parameters:
channelNumber - the channel number to allocate
Returns:
a new channel descriptor, or null if this channel number is already in use
Throws:
java.io.IOException - if an I/O problem is encountered

close

void close()
           throws java.io.IOException
Close this connection and all its channels. This method will wait infinitely for all the close operations to complete.

Throws:
java.io.IOException - if an I/O problem is encountered

close

void close(int timeout)
           throws java.io.IOException
Close this connection and all its channels This method will wait with the given timeout for all the close operations to complete. If timeout is reached then socket is forced to close

Parameters:
timeout - timeout (in milioseconds) for completing all the close-related operations, use -1 for infinity
Throws:
java.io.IOException - if an I/O problem is encountered

abort

void abort()
Abort this connection and all its channels. This method will force the connection to close. It will silently discard any exceptions enountered in close operations


abort

void abort(int timeout)
Abort this connection and all its channels. This method behaves in a similar way as abort(), with the only difference that it will wait with a provided timeout for all the close operations to complete. If timeout is reached socket is forced to close.

Parameters:
timeout - timeout (in miliseconds) for completing all the close-related operations, use -1 for infinity