Spring AMQP

org.springframework.amqp.rabbit.listener
Class BlockingQueueConsumer

java.lang.Object
  extended by org.springframework.amqp.rabbit.listener.BlockingQueueConsumer

public class BlockingQueueConsumer
extends Object

Specialized consumer encapsulating knowledge of the broker connections and having its own lifecycle (start and stop).

Author:
Mark Pollack, Dave Syer

Constructor Summary
BlockingQueueConsumer(ConnectionFactory connectionFactory, MessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter, AcknowledgeMode acknowledgeMode, boolean transactional, int prefetchCount, String... queues)
          Create a consumer.
 
Method Summary
 boolean commitIfNecessary(boolean locallyTransacted)
          Perform a commit or message acknowledgement, as appropriate.
 com.rabbitmq.client.Channel getChannel()
           
 String getConsumerTag()
           
 Message nextMessage()
          Main application-side API: wait for the next message delivery and return it.
 Message nextMessage(long timeout)
          Main application-side API: wait for the next message delivery and return it.
 void rollbackOnExceptionIfNecessary(Throwable ex)
          Perform a rollback, handling rollback exceptions properly.
 void start()
           
 void stop()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockingQueueConsumer

public BlockingQueueConsumer(ConnectionFactory connectionFactory,
                             MessagePropertiesConverter messagePropertiesConverter,
                             ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter,
                             AcknowledgeMode acknowledgeMode,
                             boolean transactional,
                             int prefetchCount,
                             String... queues)
Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started.

Method Detail

getChannel

public com.rabbitmq.client.Channel getChannel()

getConsumerTag

public String getConsumerTag()

nextMessage

public Message nextMessage()
                    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

nextMessage

public Message nextMessage(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

start

public void start()
           throws AmqpException
Throws:
AmqpException

stop

public void stop()

toString

public String toString()
Overrides:
toString in class Object

rollbackOnExceptionIfNecessary

public void rollbackOnExceptionIfNecessary(Throwable ex)
                                    throws Exception
Perform a rollback, handling rollback exceptions properly.

Parameters:
ex - the thrown application exception or error
Throws:
Exception - in case of a rollback error

commitIfNecessary

public boolean commitIfNecessary(boolean locallyTransacted)
                          throws IOException
Perform a commit or message acknowledgement, as appropriate.

Parameters:
locallyTransacted -
Throws:
IOException

Spring AMQP

Copyright © 2011. All Rights Reserved.