com.rabbitmq.client
Interface Channel

All Superinterfaces:
ShutdownNotifier
All Known Implementing Classes:
ChannelN

public interface Channel
extends ShutdownNotifier

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

To open a channel,

 Connection conn = ...;
 Channel channel = conn.createChannel();
 

Public API:

While a Channel can be used by multiple threads, it's important to ensure that only one thread executes a command at once. Concurrent execution of commands will likely cause an UnexpectedFrameError to be thrown.


Method Summary
 void abort()
          Abort this channel with the AMQP.REPLY_SUCCESS close code and message 'OK'.
 void abort(int closeCode, java.lang.String closeMessage)
          Abort this channel.
 void basicAck(long deliveryTag, boolean multiple)
          Acknowledge one or several received messages.
 void basicCancel(java.lang.String consumerTag)
          Cancel a consumer.
 java.lang.String basicConsume(java.lang.String queue, boolean noAck, Consumer callback)
          Start a non-nolocal, non-exclusive consumer, with a server-generated consumerTag.
 java.lang.String basicConsume(java.lang.String queue, boolean noAck, java.lang.String consumerTag, boolean noLocal, boolean exclusive, Consumer callback)
          Start a consumer.
 java.lang.String basicConsume(java.lang.String queue, boolean noAck, java.lang.String consumerTag, Consumer callback)
          Start a non-nolocal, non-exclusive consumer.
 java.lang.String basicConsume(java.lang.String queue, Consumer callback)
          Start a non-nolocal, non-exclusive consumer, with explicit acknowledgements required and a server-generated consumerTag.
 GetResponse basicGet(java.lang.String queue, boolean noAck)
          Retrieve a message from a queue using AMQP.Basic.Get
 void basicPublish(java.lang.String exchange, java.lang.String routingKey, AMQP.BasicProperties props, byte[] body)
          Publish a message with both "mandatory" and "immediate" flags set to false
 void basicPublish(java.lang.String exchange, java.lang.String routingKey, boolean mandatory, boolean immediate, AMQP.BasicProperties props, byte[] body)
          Publish a message
 void basicQos(int prefetchCount)
          Request a specific prefetchCount "quality of service" settings for this channel.
 void basicQos(int prefetchSize, int prefetchCount, boolean global)
          Request specific "quality of service" settings.
 void basicRecoverAsync(boolean requeue)
          Ask the broker to resend unacknowledged messages.
 void close()
          Close this channel with the AMQP.REPLY_SUCCESS close code and message 'OK'.
 void close(int closeCode, java.lang.String closeMessage)
          Close this channel.
 AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange, java.lang.String type)
          Actively declare a non-autodelete, non-durable exchange with no extra arguments
 AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange, java.lang.String type, boolean durable)
          Actively declare a non-autodelete exchange with no extra arguments
 AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange, java.lang.String type, boolean passive, boolean durable, boolean autoDelete, java.util.Map<java.lang.String,java.lang.Object> arguments)
          Declare an exchange, via an interface that allows the complete set of arguments The name of the new queue is held in the "queue" field of the AMQP.Queue.DeclareOk result.
 AMQP.Exchange.DeleteOk exchangeDelete(java.lang.String exchange)
          Delete an exchange, without regard for whether it is in use or not
 AMQP.Exchange.DeleteOk exchangeDelete(java.lang.String exchange, boolean ifUnused)
          Delete an exchange
 int getChannelNumber()
          Retrieve this channel's channel number.
 Connection getConnection()
          Retrieve the connection which carries this channel.
 ReturnListener getReturnListener()
          Return the current ReturnListener.
 AMQP.Queue.BindOk queueBind(java.lang.String queue, java.lang.String exchange, java.lang.String routingKey)
          Bind a queue to an exchange, with no extra arguments.
 AMQP.Queue.BindOk queueBind(java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
          Bind a queue to an exchange.
 AMQP.Queue.DeclareOk queueDeclare()
          Actively declare a server-named exclusive, autodelete, non-durable queue.
 AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue)
          Actively declare a non-exclusive, non-autodelete, non-durable queue
 AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue, boolean durable)
          Actively declare a non-exclusive, non-autodelete queue The name of the new queue is held in the "queue" field of the AMQP.Queue.DeclareOk result.
 AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue, boolean passive, boolean durable, boolean exclusive, boolean autoDelete, java.util.Map<java.lang.String,java.lang.Object> arguments)
          Declare a queue
 AMQP.Queue.DeleteOk queueDelete(java.lang.String queue)
          Delete a queue, without regard for whether it is in use or has messages on it
 AMQP.Queue.DeleteOk queueDelete(java.lang.String queue, boolean ifUnused, boolean ifEmpty)
          Delete a queue
 AMQP.Queue.PurgeOk queuePurge(java.lang.String queue)
          Purges the contents of the given queue and awaits a completion.
 AMQP.Queue.PurgeOk queuePurge(java.lang.String queue, boolean nowait)
          Purges the contents of the given queue.
 AMQP.Queue.UnbindOk queueUnbind(java.lang.String queue, java.lang.String exchange, java.lang.String routingKey)
          Unbinds a queue from an exchange, with no extra arguments.
 AMQP.Queue.UnbindOk queueUnbind(java.lang.String queue, java.lang.String exchange, java.lang.String routingKey, java.util.Map<java.lang.String,java.lang.Object> arguments)
          Unbind a queue from an exchange.
 void setReturnListener(ReturnListener listener)
          Set the current ReturnListener.
 AMQP.Tx.CommitOk txCommit()
          Commits a TX transaction on this channel.
 AMQP.Tx.RollbackOk txRollback()
          Rolls back a TX transaction on this channel.
 AMQP.Tx.SelectOk txSelect()
          Enables TX mode on this channel.
 
Methods inherited from interface com.rabbitmq.client.ShutdownNotifier
addShutdownListener, getCloseReason, isOpen, notifyListeners, removeShutdownListener
 

Method Detail

getChannelNumber

int getChannelNumber()
Retrieve this channel's channel number.

Returns:
the channel number

getConnection

Connection getConnection()
Retrieve the connection which carries this channel.

Returns:
the underlying Connection

close

void close()
           throws java.io.IOException
Close this channel with the AMQP.REPLY_SUCCESS close code and message 'OK'.

Throws:
java.io.IOException - if an error is encountered

close

void close(int closeCode,
           java.lang.String closeMessage)
           throws java.io.IOException
Close this channel.

Parameters:
closeCode - the close code (See under "Reply Codes" in the AMQP specification)
closeMessage - a message indicating the reason for closing the connection
Throws:
java.io.IOException - if an error is encountered

abort

void abort()
           throws java.io.IOException
Abort this channel with the AMQP.REPLY_SUCCESS close code and message 'OK'. Forces the channel to close and waits for the close operation to complete. Any encountered exceptions in the close operation are silently discarded.

Throws:
java.io.IOException

abort

void abort(int closeCode,
           java.lang.String closeMessage)
           throws java.io.IOException
Abort this channel. Forces the channel to close and waits for the close operation to complete. Any encountered exceptions in the close operation are silently discarded.

Throws:
java.io.IOException

getReturnListener

ReturnListener getReturnListener()
Return the current ReturnListener.

Returns:
an interface to the current return listener

setReturnListener

void setReturnListener(ReturnListener listener)
Set the current ReturnListener.

Parameters:
listener - the listener to use, or null indicating "don't use one".

basicQos

void basicQos(int prefetchSize,
              int prefetchCount,
              boolean global)
              throws java.io.IOException
Request specific "quality of service" settings. These settings impose limits on the amount of data the server will deliver to consumers before requiring the receipt of acknowledgements. Thus they provide a means of consumer-initiated flow control.

Parameters:
prefetchSize - maximum amount of content (measured in octets) that the server will deliver, 0 if unlimited
prefetchCount - maximum number of messages that the server will deliver, 0 if unlimited
global - true if the settings should be applied to the entire connection rather than just the current channel
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Qos

basicQos

void basicQos(int prefetchCount)
              throws java.io.IOException
Request a specific prefetchCount "quality of service" settings for this channel.

Parameters:
prefetchCount - maximum number of messages that the server will deliver, 0 if unlimited
Throws:
java.io.IOException - if an error is encountered
See Also:
basicQos(int, int, boolean)

basicPublish

void basicPublish(java.lang.String exchange,
                  java.lang.String routingKey,
                  AMQP.BasicProperties props,
                  byte[] body)
                  throws java.io.IOException
Publish a message with both "mandatory" and "immediate" flags set to false

Parameters:
exchange - the exchange to publish the message to
routingKey - the routing key
props - other properties for the message - routing headers etc
body - the message body
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Publish

basicPublish

void basicPublish(java.lang.String exchange,
                  java.lang.String routingKey,
                  boolean mandatory,
                  boolean immediate,
                  AMQP.BasicProperties props,
                  byte[] body)
                  throws java.io.IOException
Publish a message

Parameters:
exchange - the exchange to publish the message to
routingKey - the routing key
mandatory - true if we are requesting a mandatory publish
immediate - true if we are requesting an immediate publish
props - other properties for the message - routing headers etc
body - the message body
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Publish

exchangeDelete

AMQP.Exchange.DeleteOk exchangeDelete(java.lang.String exchange)
                                      throws java.io.IOException
Delete an exchange, without regard for whether it is in use or not

Parameters:
exchange - the name of the exchange
Returns:
a deletion-confirm method to indicate the exchange was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Exchange.Delete, AMQP.Exchange.DeleteOk

exchangeDeclare

AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange,
                                        java.lang.String type)
                                        throws java.io.IOException
Actively declare a non-autodelete, non-durable exchange with no extra arguments

Parameters:
exchange - the name of the exchange
type - the exchange type
Returns:
a deletion-confirm method to indicate the exchange was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Exchange.Declare, AMQP.Exchange.DeclareOk

exchangeDelete

AMQP.Exchange.DeleteOk exchangeDelete(java.lang.String exchange,
                                      boolean ifUnused)
                                      throws java.io.IOException
Delete an exchange

Parameters:
exchange - the name of the exchange
ifUnused - true to indicate that the exchange is only to be deleted if it is unused
Returns:
a deletion-confirm method to indicate the exchange was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Exchange.Delete, AMQP.Exchange.DeleteOk

exchangeDeclare

AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange,
                                        java.lang.String type,
                                        boolean durable)
                                        throws java.io.IOException
Actively declare a non-autodelete exchange with no extra arguments

Parameters:
exchange - the name of the exchange
type - the exchange type
durable - true if we are declaring a durable exchange (the exchange will survive a server restart)
Returns:
a declaration-confirm method to indicate the exchange was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Exchange.Declare, AMQP.Exchange.DeclareOk

exchangeDeclare

AMQP.Exchange.DeclareOk exchangeDeclare(java.lang.String exchange,
                                        java.lang.String type,
                                        boolean passive,
                                        boolean durable,
                                        boolean autoDelete,
                                        java.util.Map<java.lang.String,java.lang.Object> arguments)
                                        throws java.io.IOException
Declare an exchange, via an interface that allows the complete set of arguments The name of the new queue is held in the "queue" field of the AMQP.Queue.DeclareOk result.

Parameters:
exchange - the name of the exchange
type - the exchange type
passive - true if we are passively declaring a exchange (asserting the exchange already exists)
durable - true if we are declaring a durable exchange (the exchange will survive a server restart)
autoDelete - true if the server should delete the exchange when it is no longer in use
arguments - other properties (construction arguments) for the exchange
Returns:
a declaration-confirm method to indicate the exchange was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Exchange.Declare, AMQP.Exchange.DeclareOk

queueDeclare

AMQP.Queue.DeclareOk queueDeclare()
                                  throws java.io.IOException
Actively declare a server-named exclusive, autodelete, non-durable queue. The name of the new queue is held in the "queue" field of the AMQP.Queue.DeclareOk result.

Returns:
a declaration-confirm method to indicate the exchange was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk

queueDeclare

AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue)
                                  throws java.io.IOException
Actively declare a non-exclusive, non-autodelete, non-durable queue

Parameters:
queue - the name of the queue
Returns:
a declaration-confirm method to indicate the queue was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk

queueDeclare

AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue,
                                  boolean durable)
                                  throws java.io.IOException
Actively declare a non-exclusive, non-autodelete queue The name of the new queue is held in the "queue" field of the AMQP.Queue.DeclareOk result.

Parameters:
queue - the name of the queue
durable - true if we are declaring a durable exchange (the exchange will survive a server restart)
Returns:
a declaration-confirm method to indicate the exchange was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk

queueDeclare

AMQP.Queue.DeclareOk queueDeclare(java.lang.String queue,
                                  boolean passive,
                                  boolean durable,
                                  boolean exclusive,
                                  boolean autoDelete,
                                  java.util.Map<java.lang.String,java.lang.Object> arguments)
                                  throws java.io.IOException
Declare a queue

Parameters:
queue - the name of the queue
passive - true if we are passively declaring a queue (asserting the queue already exists)
durable - true if we are declaring a durable queue (the queue will survive a server restart)
exclusive - true if we are declaring an exclusive queue
autoDelete - true if we are declaring an autodelete queue (server will delete it when no longer in use)
arguments - other properties (construction arguments) for the queue
Returns:
a declaration-confirm method to indicate the queue was successfully declared
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk

queueDelete

AMQP.Queue.DeleteOk queueDelete(java.lang.String queue)
                                throws java.io.IOException
Delete a queue, without regard for whether it is in use or has messages on it

Parameters:
queue - the name of the queue
Returns:
a deletion-confirm method to indicate the queue was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Delete, AMQP.Queue.DeleteOk

queueDelete

AMQP.Queue.DeleteOk queueDelete(java.lang.String queue,
                                boolean ifUnused,
                                boolean ifEmpty)
                                throws java.io.IOException
Delete a queue

Parameters:
queue - the name of the queue
ifUnused - true if the queue should be deleted only if not in use
ifEmpty - true if the queue should be deleted only if empty
Returns:
a deletion-confirm method to indicate the queue was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Delete, AMQP.Queue.DeleteOk

queueBind

AMQP.Queue.BindOk queueBind(java.lang.String queue,
                            java.lang.String exchange,
                            java.lang.String routingKey)
                            throws java.io.IOException
Bind a queue to an exchange, with no extra arguments.

Parameters:
queue - the name of the queue
exchange - the name of the exchange
routingKey - the routine key to use for the binding
Returns:
a binding-confirm method if the binding was successfully created
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Bind, AMQP.Queue.BindOk

queueBind

AMQP.Queue.BindOk queueBind(java.lang.String queue,
                            java.lang.String exchange,
                            java.lang.String routingKey,
                            java.util.Map<java.lang.String,java.lang.Object> arguments)
                            throws java.io.IOException
Bind a queue to an exchange.

Parameters:
queue - the name of the queue
exchange - the name of the exchange
routingKey - the routine key to use for the binding
arguments - other properties (binding parameters)
Returns:
a binding-confirm method if the binding was successfully created
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Bind, AMQP.Queue.BindOk

queueUnbind

AMQP.Queue.UnbindOk queueUnbind(java.lang.String queue,
                                java.lang.String exchange,
                                java.lang.String routingKey)
                                throws java.io.IOException
Unbinds a queue from an exchange, with no extra arguments.

Parameters:
queue - the name of the queue
exchange - the name of the exchange
routingKey - the routine key to use for the binding
Returns:
an unbinding-confirm method if the binding was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Unbind, AMQP.Queue.UnbindOk

queueUnbind

AMQP.Queue.UnbindOk queueUnbind(java.lang.String queue,
                                java.lang.String exchange,
                                java.lang.String routingKey,
                                java.util.Map<java.lang.String,java.lang.Object> arguments)
                                throws java.io.IOException
Unbind a queue from an exchange.

Parameters:
queue - the name of the queue
exchange - the name of the exchange
routingKey - the routine key to use for the binding
arguments - other properties (binding parameters)
Returns:
an unbinding-confirm method if the binding was successfully deleted
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Unbind, AMQP.Queue.UnbindOk

queuePurge

AMQP.Queue.PurgeOk queuePurge(java.lang.String queue)
                              throws java.io.IOException
Purges the contents of the given queue and awaits a completion.

Parameters:
queue - the name of the queue
Returns:
a purge-confirm method if the purge was executed succesfully
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Purge, AMQP.Queue.PurgeOk

queuePurge

AMQP.Queue.PurgeOk queuePurge(java.lang.String queue,
                              boolean nowait)
                              throws java.io.IOException
Purges the contents of the given queue.

Parameters:
queue - the name of the queue
nowait - whether to await completion of the purge
Returns:
a purge-confirm method if the purge was executed succesfully
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Queue.Purge, AMQP.Queue.PurgeOk

basicGet

GetResponse basicGet(java.lang.String queue,
                     boolean noAck)
                     throws java.io.IOException
Retrieve a message from a queue using AMQP.Basic.Get

Parameters:
queue - the name of the queue
noAck - true if no handshake is required
Returns:
a GetResponse containing the retrieved message data
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Get, AMQP.Basic.GetOk, AMQP.Basic.GetEmpty

basicAck

void basicAck(long deliveryTag,
              boolean multiple)
              throws java.io.IOException
Acknowledge one or several received messages. Supply the deliveryTag from the AMQP.Basic.GetOk or AMQP.Basic.Deliver method containing the received message being acknowledged.

Parameters:
deliveryTag - the tag from the received AMQP.Basic.GetOk or AMQP.Basic.Deliver
multiple - true if we are acknowledging multiple messages with the same delivery tag
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Ack

basicConsume

java.lang.String basicConsume(java.lang.String queue,
                              Consumer callback)
                              throws java.io.IOException
Start a non-nolocal, non-exclusive consumer, with explicit acknowledgements required and a server-generated consumerTag.

Parameters:
queue - the name of the queue
callback - an interface to the consumer object
Returns:
the consumerTag generated by the server
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Consume, AMQP.Basic.ConsumeOk, basicAck(long, boolean), basicConsume(String,boolean, String,boolean,boolean, Consumer)

basicConsume

java.lang.String basicConsume(java.lang.String queue,
                              boolean noAck,
                              Consumer callback)
                              throws java.io.IOException
Start a non-nolocal, non-exclusive consumer, with a server-generated consumerTag.

Parameters:
queue - the name of the queue
noAck - true if no handshake is required
callback - an interface to the consumer object
Returns:
the consumerTag generated by the server
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Consume, AMQP.Basic.ConsumeOk, basicConsume(String,boolean, String,boolean,boolean, Consumer)

basicConsume

java.lang.String basicConsume(java.lang.String queue,
                              boolean noAck,
                              java.lang.String consumerTag,
                              Consumer callback)
                              throws java.io.IOException
Start a non-nolocal, non-exclusive consumer.

Parameters:
queue - the name of the queue
noAck - true if no handshake is required
consumerTag - a client-generated consumer tag to establish context
callback - an interface to the consumer object
Returns:
the consumerTag associated with the new consumer
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Consume, AMQP.Basic.ConsumeOk, basicConsume(String,boolean, String,boolean,boolean, Consumer)

basicConsume

java.lang.String basicConsume(java.lang.String queue,
                              boolean noAck,
                              java.lang.String consumerTag,
                              boolean noLocal,
                              boolean exclusive,
                              Consumer callback)
                              throws java.io.IOException
Start a consumer. Calls the consumer's Consumer.handleConsumeOk(java.lang.String) method before returning.

Parameters:
queue - the name of the queue
noAck - true if no handshake is required
consumerTag - a client-generated consumer tag to establish context
noLocal - flag set to true unless server local buffering is required
exclusive - true if this is an exclusive consumer
callback - an interface to the consumer object
Returns:
the consumerTag associated with the new consumer
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Consume, AMQP.Basic.ConsumeOk

basicCancel

void basicCancel(java.lang.String consumerTag)
                 throws java.io.IOException
Cancel a consumer. Calls the consumer's Consumer.handleCancelOk(java.lang.String) method before returning.

Parameters:
consumerTag - a client- or server-generated consumer tag to establish context
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Basic.Cancel, AMQP.Basic.CancelOk

basicRecoverAsync

void basicRecoverAsync(boolean requeue)
                       throws java.io.IOException
Ask the broker to resend unacknowledged messages. In 0-8 basic.recover is asynchronous; in 0-9-1 it is synchronous, and the new, deprecated method basic.recover_async is asynchronous. To avoid this API changing, this is named for the latter, and will be deprecated.

Parameters:
requeue - If true, messages will be requeued and possibly delivered to a different consumer. If false, messages will be redelivered to the same consumer.
Throws:
java.io.IOException

txSelect

AMQP.Tx.SelectOk txSelect()
                          throws java.io.IOException
Enables TX mode on this channel.

Returns:
a transaction-selection method to indicate the transaction was successfully initiated
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Tx.Select, AMQP.Tx.SelectOk

txCommit

AMQP.Tx.CommitOk txCommit()
                          throws java.io.IOException
Commits a TX transaction on this channel.

Returns:
a transaction-commit method to indicate the transaction was successfully committed
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Tx.Commit, AMQP.Tx.CommitOk

txRollback

AMQP.Tx.RollbackOk txRollback()
                              throws java.io.IOException
Rolls back a TX transaction on this channel.

Returns:
a transaction-rollback method to indicate the transaction was successfully rolled back
Throws:
java.io.IOException - if an error is encountered
See Also:
AMQP.Tx.Rollback, AMQP.Tx.RollbackOk