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

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

Introduction

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

Prototype

@Override
public final boolean isRunning() 

Source Link

Document

Determine whether this container is currently running, that is, whether it has been started and not stopped yet.

Usage

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

@Test
public void testNonManagedContainerDoesntStartWhenConnectionFactoryDestroyed() throws Exception {
    CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
    ApplicationContext context = mock(ApplicationContext.class);
    cf.setApplicationContext(context);//from w w  w  .  j  av  a  2  s.co  m

    cf.addConnectionListener(connection -> {
        cf.onApplicationEvent(new ContextClosedEvent(context));
        cf.stop();
        cf.destroy();
    });

    DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
    container.setMessageListener(m -> {
    });
    container.setQueueNames(Q1);
    container.setBeanName("stopAfterDestroyBeforeStart");
    container.afterPropertiesSet();
    container.start();

    int n = 0;
    while (n++ < 100 && container.isRunning()) {
        Thread.sleep(100);
    }
    assertFalse(container.isRunning());
}

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

@Test
public void testNonManagedContainerStopsWhenConnectionFactoryDestroyed() throws Exception {
    CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
    ApplicationContext context = mock(ApplicationContext.class);
    cf.setApplicationContext(context);/*from  w  w w . ja  v  a2  s .  c  om*/
    DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
    final CountDownLatch latch = new CountDownLatch(1);
    container.setMessageListener(m -> {
        latch.countDown();
    });
    container.setQueueNames(Q1);
    container.setBeanName("stopAfterDestroy");
    container.setIdleEventInterval(500);
    container.setFailedDeclarationRetryInterval(500);
    container.afterPropertiesSet();
    container.start();
    new RabbitTemplate(cf).convertAndSend(Q1, "foo");
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    cf.onApplicationEvent(new ContextClosedEvent(context));
    cf.stop();
    cf.destroy();
    int n = 0;
    while (n++ < 100 && container.isRunning()) {
        Thread.sleep(100);
    }
    assertFalse(container.isRunning());
}