Example usage for org.springframework.amqp.rabbit.connection ConnectionFactoryUtils getTransactionalResourceHolder

List of usage examples for org.springframework.amqp.rabbit.connection ConnectionFactoryUtils getTransactionalResourceHolder

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.connection ConnectionFactoryUtils getTransactionalResourceHolder.

Prototype

public static RabbitResourceHolder getTransactionalResourceHolder(final ConnectionFactory connectionFactory,
        final boolean synchedLocalTransactionAllowed) 

Source Link

Document

Obtain a RabbitMQ Channel that is synchronized with the current transaction, if any.

Usage

From source file:org.springframework.amqp.rabbit.connection.RabbitAccessor.java

protected RabbitResourceHolder getTransactionalResourceHolder() {
    RabbitResourceHolder holder = ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory,
            isChannelTransacted());//from  w  w  w . j  av  a2 s  . c  o  m
    return holder;
}

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

public void start() throws AmqpException {
    if (logger.isDebugEnabled()) {
        logger.debug("Starting consumer " + this);
    }//  w w  w . j  a  v  a2  s . c  o m
    this.channel = ConnectionFactoryUtils.getTransactionalResourceHolder(connectionFactory, transactional)
            .getChannel();
    this.consumer = new InternalConsumer(channel);
    this.deliveryTags.clear();
    this.activeObjectCounter.add(this);
    int passiveDeclareTries = 3; // mirrored queue might be being moved
    do {
        try {
            if (!acknowledgeMode.isAutoAck()) {
                // Set basicQos before calling basicConsume (otherwise if we
                // are not acking the broker
                // will send blocks of 100 messages)
                channel.basicQos(prefetchCount);
            }
            for (int i = 0; i < queues.length; i++) {
                channel.queueDeclarePassive(queues[i]);
            }
            passiveDeclareTries = 0;
        } catch (IOException e) {
            if (passiveDeclareTries > 0 && channel.isOpen()) {
                if (logger.isWarnEnabled()) {
                    logger.warn("Reconnect failed; retries left=" + (passiveDeclareTries - 1), e);
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e1) {
                        Thread.currentThread().interrupt();
                    }
                }
            } else {
                this.activeObjectCounter.release(this);
                throw new FatalListenerStartupException(
                        "Cannot prepare queue for listener. "
                                + "Either the queue doesn't exist or the broker will not allow us to use it.",
                        e);
            }
        }
    } while (passiveDeclareTries-- > 0);

    try {
        for (int i = 0; i < queues.length; i++) {
            channel.basicConsume(queues[i], acknowledgeMode.isAutoAck(), consumer);
            if (logger.isDebugEnabled()) {
                logger.debug("Started on queue '" + queues[i] + "': " + this);
            }
        }
    } catch (IOException e) {
        throw RabbitUtils.convertRabbitAccessException(e);
    }
}

From source file:org.springframework.amqp.rabbit.support.RabbitAccessor.java

protected RabbitResourceHolder getTransactionalResourceHolder() {
    RabbitResourceHolder holder = ConnectionFactoryUtils.getTransactionalResourceHolder(this.connectionFactory,
            isChannelTransacted());// ww w  .  j a v  a2  s .  c om
    if (isChannelTransacted()) {
        holder.declareTransactional();
    }
    return holder;
}