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

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

Introduction

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

Prototype

public final boolean isActive() 

Source Link

Usage

From source file:com.jbrisbin.groovy.mqdsl.RabbitMQBuilder.java

public boolean isActive() {
    for (SimpleMessageListenerContainer c : listenerContainers) {
        if (c.isActive()) {
            return true;
        }/*from w w  w  .jav a 2s  .c  om*/
    }
    return false;
}

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 -> {//  ww w  .j  a v  a  2 s  .c om
        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));
}