List of usage examples for org.springframework.amqp.rabbit.connection RabbitUtils isMismatchedQueueArgs
public static boolean isMismatchedQueueArgs(Exception e)
From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.rabbitAdmin != null) { try {/*from w w w. ja v a2s . co m*/ this.rabbitAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } }
From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java
/** * Use {@link RabbitAdmin#initialize()} to redeclare everything if necessary. * Since auto deletion of a queue can cause upstream elements * (bindings, exchanges) to be deleted too, everything needs to be redeclared if * a queue is missing.// w w w . ja va 2 s. c o m * Declaration is idempotent so, aside from some network chatter, there is no issue, * and we only will do it if we detect our queue is gone. * <p> * In general it makes sense only for the 'auto-delete' or 'expired' queues, * but with the server TTL policy we don't have ability to determine 'expiration' * option for the queue. * <p> * Starting with version 1.6, if * {@link #setMismatchedQueuesFatal(boolean) mismatchedQueuesFatal} is true, * the declarations are always attempted during restart so the listener will * fail with a fatal error if mismatches occur. */ protected synchronized void redeclareElementsIfNecessary() { RabbitAdmin rabbitAdmin = getRabbitAdmin(); if (rabbitAdmin == null || !isAutoDeclare()) { return; } try { ApplicationContext applicationContext = this.getApplicationContext(); if (applicationContext != null) { Set<String> queueNames = this.getQueueNamesAsSet(); Map<String, Queue> queueBeans = applicationContext.getBeansOfType(Queue.class); for (Entry<String, Queue> entry : queueBeans.entrySet()) { Queue queue = entry.getValue(); if (isMismatchedQueuesFatal() || (queueNames.contains(queue.getName()) && rabbitAdmin.getQueueProperties(queue.getName()) == null)) { if (logger.isDebugEnabled()) { logger.debug("Redeclaring context exchanges, queues, bindings."); } rabbitAdmin.initialize(); return; } } } } catch (Exception e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } logger.error("Failed to check/redeclare auto-delete queue(s).", e); } }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
private void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.rabbitAdmin != null) { try {/*from w w w. j av a2 s .c om*/ this.rabbitAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } }
From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java
/** * Use {@link RabbitAdmin#initialize()} to redeclare everything if necessary. * Since auto deletion of a queue can cause upstream elements * (bindings, exchanges) to be deleted too, everything needs to be redeclared if * a queue is missing./*from w w w . j a v a2 s . c o m*/ * Declaration is idempotent so, aside from some network chatter, there is no issue, * and we only will do it if we detect our queue is gone. * <p> * In general it makes sense only for the 'auto-delete' or 'expired' queues, * but with the server TTL policy we don't have ability to determine 'expiration' * option for the queue. * <p> * Starting with version 1.6, if * {@link #setMismatchedQueuesFatal(boolean) mismatchedQueuesFatal} is true, * the declarations are always attempted during restart so the listener will * fail with a fatal error if mismatches occur. */ private synchronized void redeclareElementsIfNecessary() { if (this.rabbitAdmin == null) { return; } try { ApplicationContext applicationContext = this.getApplicationContext(); if (applicationContext != null) { Set<String> queueNames = this.getQueueNamesAsSet(); Map<String, Queue> queueBeans = applicationContext.getBeansOfType(Queue.class); for (Entry<String, Queue> entry : queueBeans.entrySet()) { Queue queue = entry.getValue(); if (this.mismatchedQueuesFatal || (queueNames.contains(queue.getName()) && this.rabbitAdmin.getQueueProperties(queue.getName()) == null)) { if (logger.isDebugEnabled()) { logger.debug("Redeclaring context exchanges, queues, bindings."); } this.rabbitAdmin.initialize(); return; } } } } catch (Exception e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } logger.error("Failed to check/redeclare auto-delete queue(s).", e); } }