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

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

Introduction

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

Prototype

public void setRetryDeclarationInterval(long retryDeclarationInterval) 

Source Link

Document

When consuming multiple queues, set the interval between declaration attempts when only a subset of the queues were available (milliseconds).

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 ava2 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();
}