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

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

Introduction

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

Prototype

public void setRecoveryBackOff(BackOff recoveryBackOff) 

Source Link

Document

Specify the BackOff for interval between recovery attempts.

Usage

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

@Test
public void testContainerNotRecoveredAfterExhaustingRecoveryBackOff() throws Exception {
    SimpleMessageListenerContainer container = spy(
            new SimpleMessageListenerContainer(mock(ConnectionFactory.class)));
    container.setQueueNames("foo");
    container.setRecoveryBackOff(new FixedBackOff(100, 3));
    container.setConcurrentConsumers(3);
    doAnswer(invocation -> {/*from w w w  . j a  v  a 2  s  .c  o  m*/
        BlockingQueueConsumer consumer = spy((BlockingQueueConsumer) invocation.callRealMethod());
        doThrow(RuntimeException.class).when(consumer).start();
        return consumer;
    }).when(container).createBlockingQueueConsumer();
    container.afterPropertiesSet();
    container.start();

    // Since backOff exhausting makes listenerContainer as invalid (calls stop()),
    // it is enough to check the listenerContainer activity
    int n = 0;
    while (container.isActive() && n++ < 100) {
        Thread.sleep(100);
    }
    assertThat(n, lessThanOrEqualTo(100));
}