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

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

Introduction

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

Prototype

public void setDeclarationRetries(int declarationRetries) 

Source Link

Document

Set the number of retries after passive queue declaration fails.

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 ava 2 s.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();
}