List of usage examples for org.springframework.amqp.core Exchange getName
String getName();
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. *//*from w w w. j a v a 2 s .c om*/ 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 declareExchanges(final Channel channel, final Exchange... exchanges) throws IOException { for (final Exchange exchange : exchanges) { if (logger.isDebugEnabled()) { logger.debug("declaring Exchange '" + exchange.getName() + "'"); }/*from w w w . j av a 2 s . co m*/ if (!isDeclaringDefaultExchange(exchange)) { channel.exchangeDeclare(exchange.getName(), exchange.getType(), exchange.isDurable(), exchange.isAutoDelete(), exchange.getArguments()); } } }
From source file:org.springframework.amqp.rabbit.core.RabbitAdmin.java
private boolean isDeclaringDefaultExchange(Exchange exchange) { if (isDefaultExchange(exchange.getName())) { if (logger.isDebugEnabled()) { logger.debug("Default exchange is pre-declared by server."); }//from w ww. ja v a2 s . c om return true; } return false; }
From source file:org.springframework.cloud.stream.binder.rabbit.provisioning.RabbitExchangeQueueProvisioner.java
private void declareExchange(final String rootName, final Exchange exchange) { try {/* ww w . j a va 2 s . c o m*/ this.rabbitAdmin.declareExchange(exchange); } catch (AmqpConnectException e) { if (this.logger.isDebugEnabled()) { this.logger.debug( "Declaration of exchange: " + exchange.getName() + " deferred - connection not available"); } } addToAutoDeclareContext(rootName + ".exchange", exchange); }
From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBus.java
/** * Try passive declaration first, in case the user has pre-configured the exchange with * incompatible arguments.//from w w w . jav a 2s. c o m * @param exchange */ private void declareExchangeIfNotPresent(final Exchange exchange) { this.rabbitTemplate.execute(new ChannelCallback<Void>() { @Override public Void doInRabbit(Channel channel) throws Exception { try { channel.exchangeDeclarePassive(exchange.getName()); } catch (IOException e) { RabbitMessageBus.this.rabbitAdmin.declareExchange(exchange); } return null; } }); }