Example usage for com.rabbitmq.client Channel waitForConfirmsOrDie

List of usage examples for com.rabbitmq.client Channel waitForConfirmsOrDie

Introduction

In this page you can find the example usage for com.rabbitmq.client Channel waitForConfirmsOrDie.

Prototype

void waitForConfirmsOrDie() throws IOException, InterruptedException;

Source Link

Document

Wait until all messages published since the last call have been either ack'd or nack'd by the broker.

Usage

From source file:org.axonframework.eventhandling.amqp.spring.SpringAMQPTerminal.java

License:Apache License

@Override
public void publish(EventMessage... events) {
    final Channel channel = connectionFactory.createConnection().createChannel(isTransactional);
    try {//from   w  w  w. jav a2  s . co  m
        if (waitForAck) {
            channel.confirmSelect();
        }
        for (EventMessage event : events) {
            AMQPMessage amqpMessage = messageConverter.createAMQPMessage(event);
            doSendMessage(channel, amqpMessage);
        }
        if (CurrentUnitOfWork.isStarted()) {
            CurrentUnitOfWork.get().registerListener(new ChannelTransactionUnitOfWorkListener(channel));
        } else if (isTransactional) {
            channel.txCommit();
        } else if (waitForAck) {
            channel.waitForConfirmsOrDie();
        }
    } catch (IOException e) {
        if (isTransactional) {
            tryRollback(channel);
        }
        throw new EventPublicationFailedException("Failed to dispatch Events to the Message Broker.", e);
    } catch (ShutdownSignalException e) {
        throw new EventPublicationFailedException("Failed to dispatch Events to the Message Broker.", e);
    } catch (InterruptedException e) {
        logger.warn("Interrupt received when waiting for message confirms.");
        Thread.currentThread().interrupt();
    } finally {
        if (!CurrentUnitOfWork.isStarted()) {
            tryClose(channel);
        }
    }
}