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

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

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.listener DirectMessageListenerContainer 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.DirectMessageListenerContainerIntegrationTests.java

@Test
public void testContainerNotRecoveredAfterExhaustingRecoveryBackOff() throws Exception {
    ConnectionFactory mockCF = mock(ConnectionFactory.class);
    given(mockCF.createConnection()).willThrow(new RuntimeException("intended - backOff test"));
    DirectMessageListenerContainer container = new DirectMessageListenerContainer(mockCF);
    container.setQueueNames("foo");
    container.setRecoveryBackOff(new FixedBackOff(100, 3));
    container.setMissingQueuesFatal(false);
    container.setBeanName("backOff");
    container.setConsumerTagStrategy(new Tag());
    container.afterPropertiesSet();//from   w  w w.  j av  a2 s. c  o m
    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);
    }
    assertFalse(container.isActive());
}