Example usage for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setMissingQueuesFatal

List of usage examples for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setMissingQueuesFatal

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener SimpleMessageListenerContainer setMissingQueuesFatal.

Prototype

@Override
public void setMissingQueuesFatal(boolean missingQueuesFatal) 

Source Link

Document

When true, if the queues are removed while the container is running, the container is stopped.

Usage

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

@Test
public void testRestartConsumerMissingQueue() throws Exception {
    Queue queue = new AnonymousQueue();
    this.template.convertAndSend(queue.getName(), "foo");

    ConnectionFactory connectionFactory = new CachingConnectionFactory("localhost", BrokerTestUtils.getPort());

    CountDownLatch latch = new CountDownLatch(1);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
    container.setMessageListener(new MessageListenerAdapter(new PojoListener(latch)));
    container.setQueues(queue);//from   w w w. j  a  v a  2s.  c  o  m
    container.setRecoveryInterval(500);
    container.setMissingQueuesFatal(false);
    container.setDeclarationRetries(1);
    container.setFailedDeclarationRetryInterval(100);
    container.setRetryDeclarationInterval(30000);
    container.afterPropertiesSet();
    container.start();

    new RabbitAdmin(connectionFactory).declareQueue(queue);
    this.template.convertAndSend(queue.getName(), "foo");

    assertTrue(latch.await(10, TimeUnit.SECONDS));

    // verify properties propagated to consumer
    BlockingQueueConsumer consumer = (BlockingQueueConsumer) TestUtils
            .getPropertyValue(container, "consumers", Map.class).keySet().iterator().next();
    assertEquals(1, TestUtils.getPropertyValue(consumer, "declarationRetries"));
    assertEquals(100L, TestUtils.getPropertyValue(consumer, "failedDeclarationRetryInterval"));
    assertEquals(30000L, TestUtils.getPropertyValue(consumer, "retryDeclarationInterval"));

    container.stop();
    ((DisposableBean) connectionFactory).destroy();
}