public class QueueingConsumer extends DefaultConsumer
Consumer with
straightforward blocking semantics.
Deprecated in favor of DefaultConsumer (see below for background).
Will be removed in next major release.
The general pattern for using QueueingConsumer is as follows:
// Create connection and channel.ConnectionFactoryfactory = new ConnectionFactory(); Connection conn = factory.newConnection();Channelch1 = conn.createChannel(); // Declare a queue and bind it to an exchange. String queueName = ch1.queueDeclare().getQueue(); ch1.queueBind(queueName, exchangeName, queueName); // Create the QueueingConsumer and have it consume from the queue QueueingConsumer consumer = newQueueingConsumer(ch1); ch1.basicConsume(queueName, false, consumer); // Process deliveries while (/* some condition * /) {QueueingConsumer.Deliverydelivery = consumer.nextDelivery(); // process delivery ch1.basicAck(delivery.getEnvelope().getDeliveryTag(), false); }
For a more complete example, see LogTail in the test/src/com/rabbitmq/examples
directory of the source distribution.
QueueingConsumer was introduced to allow
applications to overcome a limitation in the way Connection
managed threads and consumer dispatching. When QueueingConsumer
was introduced, callbacks to Consumers were made on the
Connection's thread. This had two main drawbacks. Firstly, the
Consumer could stall the processing of all
Channels on the Connection. Secondly, if a
Consumer made a recursive synchronous call into its
Channel the client would deadlock.
QueueingConsumer provided client code with an easy way to
obviate this problem by queueing incoming messages and processing them on
a separate, application-managed thread.
The threading behaviour of Connection and Channel
has been changed so that each Channel uses a distinct thread
for dispatching to Consumers. This prevents
Consumers on one Channel holding up
Consumers on another and it also prevents recursive calls from
deadlocking the client.
As such, it is now safe to implement Consumer directly or
to extend DefaultConsumer and QueueingConsumer
is a lot less relevant.
| Modifier and Type | Class and Description |
|---|---|
static class |
QueueingConsumer.Delivery
Deprecated.
Encapsulates an arbitrary message - simple "bean" holder structure.
|
| Constructor and Description |
|---|
QueueingConsumer(Channel ch)
Deprecated.
|
QueueingConsumer(Channel ch,
BlockingQueue<QueueingConsumer.Delivery> q)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
handleCancel(String consumerTag)
Deprecated.
No-op implementation of
Consumer.handleCancel(String) |
void |
handleDelivery(String consumerTag,
Envelope envelope,
AMQP.BasicProperties properties,
byte[] body)
Deprecated.
|
void |
handleShutdownSignal(String consumerTag,
ShutdownSignalException sig)
Deprecated.
No-op implementation of
Consumer.handleShutdownSignal(java.lang.String, com.rabbitmq.client.ShutdownSignalException). |
QueueingConsumer.Delivery |
nextDelivery()
Deprecated.
Main application-side API: wait for the next message delivery and return it.
|
QueueingConsumer.Delivery |
nextDelivery(long timeout)
Deprecated.
Main application-side API: wait for the next message delivery and return it.
|
getChannel, getConsumerTag, handleCancelOk, handleConsumeOk, handleRecoverOkpublic QueueingConsumer(Channel ch)
public QueueingConsumer(Channel ch, BlockingQueue<QueueingConsumer.Delivery> q)
public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig)
DefaultConsumerConsumer.handleShutdownSignal(java.lang.String, com.rabbitmq.client.ShutdownSignalException).handleShutdownSignal in interface ConsumerhandleShutdownSignal in class DefaultConsumerconsumerTag - the consumer tag associated with the consumersig - a ShutdownSignalException indicating the reason for the shut downpublic void handleCancel(String consumerTag) throws IOException
DefaultConsumerConsumer.handleCancel(String)handleCancel in interface ConsumerhandleCancel in class DefaultConsumerconsumerTag - the defined consumer tag (client- or server-generated)IOExceptionpublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException
DefaultConsumerConsumer.handleDelivery(java.lang.String, com.rabbitmq.client.Envelope, com.rabbitmq.client.AMQP.BasicProperties, byte[]).handleDelivery in interface ConsumerhandleDelivery in class DefaultConsumerconsumerTag - the consumer tag associated with the consumerenvelope - packaging data for the messageproperties - content header data for the messagebody - the message body (opaque, client-specific byte array)IOException - if the consumer encounters an I/O error while processing the messageEnvelopepublic QueueingConsumer.Delivery nextDelivery() throws InterruptedException, ShutdownSignalException, ConsumerCancelledException
InterruptedException - if an interrupt is received while waitingShutdownSignalException - if the connection is shut down while waitingConsumerCancelledException - if this consumer is cancelled while waitingpublic QueueingConsumer.Delivery nextDelivery(long timeout) throws InterruptedException, ShutdownSignalException, ConsumerCancelledException
timeout - timeout in millisecondInterruptedException - if an interrupt is received while waitingShutdownSignalException - if the connection is shut down while waitingConsumerCancelledException - if this consumer is cancelled while waitingCopyright © 2016 Pivotal Software, Inc.. All rights reserved.