Spring AMQP

org.springframework.amqp.rabbit.listener
Class BlockingQueueConsumer

java.lang.Object
  extended by com.rabbitmq.client.DefaultConsumer
      extended by org.springframework.amqp.rabbit.listener.BlockingQueueConsumer
All Implemented Interfaces:
com.rabbitmq.client.Consumer

public class BlockingQueueConsumer
extends com.rabbitmq.client.DefaultConsumer

Variation on QueueingConsumer in RabbitMQ, uses 'put' instead of 'add' and stored a reference to the consumerTag that was returned when this Consumer was registered with the channel so as to make it easy to close the consumer when shutting down.

Author:
Mark Pollack

Nested Class Summary
static class BlockingQueueConsumer.Delivery
          Encapsulates an arbitrary message - simple "bean" holder structure.
 
Constructor Summary
BlockingQueueConsumer(com.rabbitmq.client.Channel ch)
           
BlockingQueueConsumer(com.rabbitmq.client.Channel ch, BlockingQueue<BlockingQueueConsumer.Delivery> q)
           
 
Method Summary
 void handleDelivery(String consumerTag, com.rabbitmq.client.Envelope envelope, com.rabbitmq.client.AMQP.BasicProperties properties, byte[] body)
           
 void handleShutdownSignal(String consumerTag, com.rabbitmq.client.ShutdownSignalException sig)
           
 BlockingQueueConsumer.Delivery nextDelivery()
          Main application-side API: wait for the next message delivery and return it.
 BlockingQueueConsumer.Delivery nextDelivery(long timeout)
          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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockingQueueConsumer

public BlockingQueueConsumer(com.rabbitmq.client.Channel ch)

BlockingQueueConsumer

public BlockingQueueConsumer(com.rabbitmq.client.Channel ch,
                             BlockingQueue<BlockingQueueConsumer.Delivery> q)
Method Detail

handleShutdownSignal

public void handleShutdownSignal(String consumerTag,
                                 com.rabbitmq.client.ShutdownSignalException sig)
Specified by:
handleShutdownSignal in interface com.rabbitmq.client.Consumer
Overrides:
handleShutdownSignal in class com.rabbitmq.client.DefaultConsumer

handleDelivery

public void handleDelivery(String consumerTag,
                           com.rabbitmq.client.Envelope envelope,
                           com.rabbitmq.client.AMQP.BasicProperties properties,
                           byte[] body)
                    throws IOException
Specified by:
handleDelivery in interface com.rabbitmq.client.Consumer
Overrides:
handleDelivery in class com.rabbitmq.client.DefaultConsumer
Throws:
IOException

nextDelivery

public BlockingQueueConsumer.Delivery nextDelivery()
                                            throws InterruptedException,
                                                   com.rabbitmq.client.ShutdownSignalException
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 waiting
com.rabbitmq.client.ShutdownSignalException - if the connection is shut down while waiting

nextDelivery

public BlockingQueueConsumer.Delivery nextDelivery(long timeout)
                                            throws InterruptedException,
                                                   com.rabbitmq.client.ShutdownSignalException
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 waiting
com.rabbitmq.client.ShutdownSignalException - if the connection is shut down while waiting

Spring AMQP

Copyright © 2010. All Rights Reserved.