public interface

Connection

implements ShutdownNotifier
com.rabbitmq.client.Connection
Known Indirect Subclasses

Class Overview

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

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

 ConnectionFactory factory = new ConnectionFactory();
 factory.setHost(hostName);
 factory.setPort(portNumber);
 factory.setVirtualHost(virtualHost);
 factory.setUsername(username);
 factory.setPassword(password);
 Connection conn = factory.newConnection();

 // Then open a channel:

 Channel channel = conn.createChannel();
 
Or, more compactly:
 ConnectionFactory factory = new ConnectionFactory();
 factory.setUri("amqp://username:password@hostName:portNumber/virtualHost");
 Connection conn = factory.newConnection();
 Channel channel = conn.createChannel()
 
Current implementations are thread-safe for code at the client API level, and in fact thread-safe internally except for code within RPC calls.

Summary

Public Methods
abstract void abort()
Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
abstract void abort(int closeCode, String closeMessage, int timeout)
Abort this connection and all its channels.
abstract void abort(int closeCode, String closeMessage)
Abort this connection and all its channels.
abstract void abort(int timeout)
Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
abstract void close(int closeCode, String closeMessage)
Close this connection and all its channels.
abstract void close()
Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
abstract void close(int timeout)
Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'.
abstract void close(int closeCode, String closeMessage, int timeout)
Close this connection and all its channels.
abstract Channel createChannel()
Create a new channel, using an internally allocated channel number.
abstract Channel createChannel(int channelNumber)
Create a new channel, using the specified channel number if possible.
abstract InetAddress getAddress()
Retrieve the host.
abstract int getChannelMax()
Get the negotiated maximum channel number.
abstract Map<StringObject> getClientProperties()
Get a copy of the map of client properties sent to the server
abstract int getFrameMax()
Get the negotiated maximum frame size.
abstract int getHeartbeat()
Get the negotiated heartbeat interval.
abstract int getPort()
Retrieve the port number.
abstract Map<StringObject> getServerProperties()
Retrieve the server properties.
[Expand]
Inherited Methods
From interface com.rabbitmq.client.ShutdownNotifier

Public Methods

public abstract void abort ()

Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. Forces the connection to close. Any encountered exceptions in the close operations are silently discarded.

public abstract void abort (int closeCode, String closeMessage, int timeout)

Abort this connection and all its channels. Forces the connection to close and waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close. Any encountered exceptions in the close operations are silently discarded.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity

public abstract void abort (int closeCode, String closeMessage)

Abort this connection and all its channels. Forces the connection to close and waits for all the close operations to complete. Any encountered exceptions in the close operations are silently discarded.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection

public abstract void abort (int timeout)

Abort this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. This method behaves in a similar way as abort(), with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.

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

public abstract void close (int closeCode, String closeMessage)

Close this connection and all its channels. Waits for all the close operations to complete.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
Throws
IOException if an I/O problem is encountered

public abstract void close ()

Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. Waits for all the close operations to complete.

Throws
IOException if an I/O problem is encountered

public abstract void close (int timeout)

Close this connection and all its channels with the com.rabbitmq.client.AMQP close code and message 'OK'. This method behaves in a similar way as close(), with the only difference that it waits with a provided timeout for all the close operations to complete. When timeout is reached the socket is forced to close.

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

public abstract void close (int closeCode, String closeMessage, int timeout)

Close this connection and all its channels. Waits with the given timeout for all the close operations to complete. When timeout is reached the socket is forced to close.

Parameters
closeCode the close code (See under "Reply Codes" in the AMQP specification)
closeMessage a message indicating the reason for closing the connection
timeout timeout (in milliseconds) for completing all the close-related operations, use -1 for infinity
Throws
IOException if an I/O problem is encountered

public abstract Channel createChannel ()

Create a new channel, using an internally allocated channel number.

Returns
  • a new channel descriptor, or null if none is available
Throws
IOException if an I/O problem is encountered

public abstract Channel createChannel (int channelNumber)

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
IOException if an I/O problem is encountered

public abstract InetAddress getAddress ()

Retrieve the host.

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

public abstract int getChannelMax ()

Get the negotiated maximum channel number. Usable channel numbers range from 1 to this number, inclusive.

Returns
  • the maximum channel number permitted for this connection.

public abstract Map<StringObject> getClientProperties ()

Get a copy of the map of client properties sent to the server

Returns
  • a copy of the map of client properties

public abstract int getFrameMax ()

Get the negotiated maximum frame size.

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

public abstract int getHeartbeat ()

Get the negotiated heartbeat interval.

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

public abstract int getPort ()

Retrieve the port number.

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

public abstract Map<StringObject> getServerProperties ()

Retrieve the server properties.

Returns
  • a map of the server properties. This typically includes the product name and version of the server.