Example usage for org.springframework.amqp.core Queue isDurable

List of usage examples for org.springframework.amqp.core Queue isDurable

Introduction

In this page you can find the example usage for org.springframework.amqp.core Queue isDurable.

Prototype

public boolean isDurable() 

Source Link

Document

A durable queue will survive a server restart.

Usage

From source file:org.springframework.amqp.rabbit.core.RabbitAdmin.java

/**
 * Declares all the exchanges, queues and bindings in the enclosing application context, if any. It should be safe
 * (but unnecessary) to call this method more than once.
 *//*w ww.  ja  v  a  2  s . c o m*/
public void initialize() {

    if (this.applicationContext == null) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug(
                    "no ApplicationContext has been set, cannot auto-declare Exchanges, Queues, and Bindings");
        }
        return;
    }

    logger.debug("Initializing declarations");
    final Collection<Exchange> exchanges = applicationContext.getBeansOfType(Exchange.class).values();
    final Collection<Queue> queues = applicationContext.getBeansOfType(Queue.class).values();
    final Collection<Binding> bindings = applicationContext.getBeansOfType(Binding.class).values();

    for (Exchange exchange : exchanges) {
        if (!exchange.isDurable()) {
            logger.warn("Auto-declaring a non-durable Exchange (" + exchange.getName()
                    + "). It will be deleted by the broker if it shuts down, and can be redeclared by closing and reopening the connection.");
        }
        if (exchange.isAutoDelete()) {
            logger.warn("Auto-declaring an auto-delete Exchange (" + exchange.getName()
                    + "). It will be deleted by the broker if not in use (if all bindings are deleted), but will only be redeclared if the connection is closed and reopened.");
        }
    }

    for (Queue queue : queues) {
        if (!queue.isDurable()) {
            logger.warn("Auto-declaring a non-durable Queue (" + queue.getName()
                    + "). It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.");
        }
        if (queue.isAutoDelete()) {
            logger.warn("Auto-declaring an auto-delete Queue (" + queue.getName()
                    + "). It will be deleted by the broker if not in use, and all messages will be lost.  Redeclared when the connection is closed and reopened.");
        }
        if (queue.isExclusive()) {
            logger.warn("Auto-declaring an exclusive Queue (" + queue.getName()
                    + "). It cannot be accessed by consumers on another connection, and will be redeclared if the connection is reopened.");
        }
    }

    rabbitTemplate.execute(new ChannelCallback<Object>() {
        public Object doInRabbit(Channel channel) throws Exception {
            declareExchanges(channel, exchanges.toArray(new Exchange[exchanges.size()]));
            declareQueues(channel, queues.toArray(new Queue[queues.size()]));
            declareBindings(channel, bindings.toArray(new Binding[bindings.size()]));
            return null;
        }
    });
    logger.debug("Declarations finished");

}

From source file:org.springframework.amqp.rabbit.core.RabbitAdmin.java

private void declareQueues(final Channel channel, final Queue... queues) throws IOException {
    for (Queue queue : queues) {
        if (!queue.getName().startsWith("amq.")) {
            if (logger.isDebugEnabled()) {
                logger.debug("declaring Queue '" + queue.getName() + "'");
            }/*w  ww  . ja v  a 2s .  c om*/
            channel.queueDeclare(queue.getName(), queue.isDurable(), queue.isExclusive(), queue.isAutoDelete(),
                    queue.getArguments());
        } else if (logger.isDebugEnabled()) {
            logger.debug("Queue with name that starts with 'amq.' cannot be declared.");
        }
    }
}