Class QueueingConsumer
- java.lang.Object
-
- com.rabbitmq.client.DefaultConsumer
-
- com.rabbitmq.client.QueueingConsumer
-
- All Implemented Interfaces:
Consumer
public class QueueingConsumer extends DefaultConsumer
Deprecated.Convenience class: an implementation ofConsumer
with straightforward blocking semantics. Deprecated in favor ofDefaultConsumer
(see below for background). Will be removed in next major release. The general pattern for using QueueingConsumer is as follows:// Create connection and channel.
ConnectionFactory
factory = new ConnectionFactory(); Connection conn = factory.newConnection();Channel
ch1 = 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.Delivery
delivery = 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.Historical Perspective
QueueingConsumer
was introduced to allow applications to overcome a limitation in the wayConnection
managed threads and consumer dispatching. WhenQueueingConsumer
was introduced, callbacks toConsumers
were made on theConnection's
thread. This had two main drawbacks. Firstly, theConsumer
could stall the processing of allChannels
on theConnection
. Secondly, if aConsumer
made a recursive synchronous call into itsChannel
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
andChannel
has been changed so that eachChannel
uses a distinct thread for dispatching toConsumers
. This preventsConsumers
on oneChannel
holding upConsumers
on another and it also prevents recursive calls from deadlocking the client. As such, it is now safe to implementConsumer
directly or to extendDefaultConsumer
andQueueingConsumer
is a lot less relevant.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueueingConsumer.Delivery
Deprecated.Encapsulates an arbitrary message - simple "bean" holder structure.
-
Constructor Summary
Constructors Constructor Description QueueingConsumer(Channel ch)
Deprecated.QueueingConsumer(Channel ch, BlockingQueue<QueueingConsumer.Delivery> q)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
handleCancel(String consumerTag)
Deprecated.No-op implementation ofConsumer.handleCancel(String)
void
handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
Deprecated.void
handleShutdownSignal(String consumerTag, ShutdownSignalException sig)
Deprecated.No-op implementation ofConsumer.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.-
Methods inherited from class com.rabbitmq.client.DefaultConsumer
getChannel, getConsumerTag, handleCancelOk, handleConsumeOk, handleRecoverOk
-
-
-
-
Constructor Detail
-
QueueingConsumer
public QueueingConsumer(Channel ch)
Deprecated.
-
QueueingConsumer
public QueueingConsumer(Channel ch, BlockingQueue<QueueingConsumer.Delivery> q)
Deprecated.
-
-
Method Detail
-
handleShutdownSignal
public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig)
Deprecated.Description copied from class:DefaultConsumer
No-op implementation ofConsumer.handleShutdownSignal(java.lang.String, com.rabbitmq.client.ShutdownSignalException)
.- Specified by:
handleShutdownSignal
in interfaceConsumer
- Overrides:
handleShutdownSignal
in classDefaultConsumer
- Parameters:
consumerTag
- the consumer tag associated with the consumersig
- aShutdownSignalException
indicating the reason for the shut down
-
handleCancel
public void handleCancel(String consumerTag) throws IOException
Deprecated.Description copied from class:DefaultConsumer
No-op implementation ofConsumer.handleCancel(String)
- Specified by:
handleCancel
in interfaceConsumer
- Overrides:
handleCancel
in classDefaultConsumer
- Parameters:
consumerTag
- the defined consumer tag (client- or server-generated)- Throws:
IOException
-
handleDelivery
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException
Deprecated.Description copied from class:DefaultConsumer
No-op implementation ofConsumer.handleDelivery(java.lang.String, com.rabbitmq.client.Envelope, com.rabbitmq.client.AMQP.BasicProperties, byte[])
.- Specified by:
handleDelivery
in interfaceConsumer
- Overrides:
handleDelivery
in classDefaultConsumer
- Parameters:
consumerTag
- 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)- Throws:
IOException
- if the consumer encounters an I/O error while processing the message- See Also:
Envelope
-
nextDelivery
public QueueingConsumer.Delivery nextDelivery() throws InterruptedException, ShutdownSignalException, ConsumerCancelledException
Deprecated.Main application-side API: wait for the next message delivery and return it.- Returns:
- the next message
- Throws:
InterruptedException
- if an interrupt is received while waitingShutdownSignalException
- if the connection is shut down while waitingConsumerCancelledException
- if this consumer is cancelled while waiting
-
nextDelivery
public QueueingConsumer.Delivery nextDelivery(long timeout) throws InterruptedException, ShutdownSignalException, ConsumerCancelledException
Deprecated.Main application-side API: wait for the next message delivery and return it.- Parameters:
timeout
- timeout in millisecond- Returns:
- the next message or null if timed out
- Throws:
InterruptedException
- if an interrupt is received while waitingShutdownSignalException
- if the connection is shut down while waitingConsumerCancelledException
- if this consumer is cancelled while waiting
-
-