Example usage for org.springframework.amqp.rabbit.listener BlockingQueueConsumer nextMessage

List of usage examples for org.springframework.amqp.rabbit.listener BlockingQueueConsumer nextMessage

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener BlockingQueueConsumer nextMessage.

Prototype

@Nullable
public Message nextMessage(long timeout) throws InterruptedException, ShutdownSignalException 

Source Link

Document

Main application-side API: wait for the next message delivery and return it.

Usage

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java

private boolean doReceiveAndExecute(BlockingQueueConsumer consumer) throws Throwable {

    Channel channel = consumer.getChannel();

    for (int i = 0; i < this.txSize; i++) {

        logger.trace("Waiting for message from consumer.");
        Message message = consumer.nextMessage(this.receiveTimeout);
        if (message == null) {
            break;
        }//  w  w  w .ja  va  2s .  c  o m
        try {
            executeListener(channel, message);
        } catch (ImmediateAcknowledgeAmqpException e) {
            break;
        } catch (Throwable ex) { //NOSONAR
            consumer.rollbackOnExceptionIfNecessary(ex);
            throw ex;
        }

    }

    return consumer.commitIfNecessary(isChannelLocallyTransacted(channel));

}