org.springframework.amqp.rabbit.listener
Class BlockingQueueConsumer

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

public class BlockingQueueConsumer
extends java.lang.Object

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


Constructor Summary
BlockingQueueConsumer(ConnectionFactory connectionFactory, MessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter, org.springframework.amqp.core.AcknowledgeMode acknowledgeMode, boolean transactional, int prefetchCount, boolean defaultRequeueRejected, java.lang.String... queues)
          Create a consumer.
BlockingQueueConsumer(ConnectionFactory connectionFactory, MessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter, org.springframework.amqp.core.AcknowledgeMode acknowledgeMode, boolean transactional, int prefetchCount, java.lang.String... queues)
          Create a consumer.
 
Method Summary
 boolean commitIfNecessary(boolean locallyTransacted)
          Perform a commit or message acknowledgement, as appropriate.
 com.rabbitmq.client.Channel getChannel()
           
 java.lang.String getConsumerTag()
           
 org.springframework.amqp.core.Message nextMessage()
          Main application-side API: wait for the next message delivery and return it.
 org.springframework.amqp.core.Message nextMessage(long timeout)
          Main application-side API: wait for the next message delivery and return it.
 void rollbackOnExceptionIfNecessary(java.lang.Throwable ex)
          Perform a rollback, handling rollback exceptions properly.
 void start()
           
 void stop()
           
 java.lang.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,
                             org.springframework.amqp.core.AcknowledgeMode acknowledgeMode,
                             boolean transactional,
                             int prefetchCount,
                             java.lang.String... queues)
Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started. RequeueRejected defaults to true.


BlockingQueueConsumer

public BlockingQueueConsumer(ConnectionFactory connectionFactory,
                             MessagePropertiesConverter messagePropertiesConverter,
                             ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter,
                             org.springframework.amqp.core.AcknowledgeMode acknowledgeMode,
                             boolean transactional,
                             int prefetchCount,
                             boolean defaultRequeueRejected,
                             java.lang.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 java.lang.String getConsumerTag()

nextMessage

public org.springframework.amqp.core.Message nextMessage()
                                                  throws java.lang.InterruptedException,
                                                         com.rabbitmq.client.ShutdownSignalException
Main application-side API: wait for the next message delivery and return it.

Returns:
the next message
Throws:
java.lang.InterruptedException - if an interrupt is received while waiting
com.rabbitmq.client.ShutdownSignalException - if the connection is shut down while waiting

nextMessage

public org.springframework.amqp.core.Message nextMessage(long timeout)
                                                  throws java.lang.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:
java.lang.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 org.springframework.amqp.AmqpException
Throws:
org.springframework.amqp.AmqpException

stop

public void stop()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

rollbackOnExceptionIfNecessary

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

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

commitIfNecessary

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

Parameters:
locallyTransacted -
Throws:
java.io.IOException