List of usage examples for org.springframework.amqp.rabbit.listener DirectMessageListenerContainer setMonitorInterval
public void setMonitorInterval(long monitorInterval)
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java
@Test public void testRecoverBrokerLoss() throws Exception { ConnectionFactory mockCF = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Channel channel = mock(Channel.class); given(connection.isOpen()).willReturn(true); given(mockCF.createConnection()).willReturn(connection); given(connection.createChannel(false)).willReturn(channel); given(channel.isOpen()).willReturn(true); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(2); ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class); final String tag = "tag"; willAnswer(i -> {/*from ww w.j av a2 s .c o m*/ latch1.countDown(); latch2.countDown(); return tag; }).given(channel).basicConsume(eq("foo"), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), consumerCaptor.capture()); DirectMessageListenerContainer container = new DirectMessageListenerContainer(mockCF); container.setQueueNames("foo"); container.setBeanName("brokerLost"); container.setConsumerTagStrategy(q -> "tag"); container.setShutdownTimeout(1); container.setMonitorInterval(200); container.setFailedDeclarationRetryInterval(200); container.afterPropertiesSet(); container.start(); assertTrue(latch1.await(10, TimeUnit.SECONDS)); given(channel.isOpen()).willReturn(false); assertTrue(latch2.await(10, TimeUnit.SECONDS)); container.setShutdownTimeout(1); container.stop(); }
From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerTests.java
@SuppressWarnings("unchecked") @Test/*w ww .j a v a 2 s. c o m*/ public void testRecoverBrokerLoss() throws Exception { ConnectionFactory mockCF = mock(ConnectionFactory.class); Connection connection = mock(Connection.class); Channel channel = mock(Channel.class); given(connection.isOpen()).willReturn(true); given(mockCF.createConnection()).willReturn(connection); given(connection.createChannel(false)).willReturn(channel); given(channel.isOpen()).willReturn(true); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(2); ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class); final String tag = "tag"; willAnswer(i -> { latch1.countDown(); latch2.countDown(); return tag; }).given(channel).basicConsume(eq("foo"), anyBoolean(), anyString(), anyBoolean(), anyBoolean(), anyMap(), consumerCaptor.capture()); DirectMessageListenerContainer container = new DirectMessageListenerContainer(mockCF); container.setQueueNames("foo"); container.setBeanName("brokerLost"); container.setConsumerTagStrategy(q -> "tag"); container.setShutdownTimeout(1); container.setMonitorInterval(200); container.setFailedDeclarationRetryInterval(200); container.afterPropertiesSet(); container.start(); assertTrue(latch1.await(10, TimeUnit.SECONDS)); given(channel.isOpen()).willReturn(false); assertTrue(latch2.await(10, TimeUnit.SECONDS)); container.setShutdownTimeout(1); container.stop(); }