List of usage examples for org.springframework.util.backoff FixedBackOff FixedBackOff
public FixedBackOff(long interval, long maxAttempts)
From source file:org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory.java
/** * @param recoveryInterval The recovery interval. * @see SimpleMessageListenerContainer#setRecoveryInterval *///www.j av a 2s . c o m public void setRecoveryInterval(Long recoveryInterval) { this.recoveryBackOff = new FixedBackOff(recoveryInterval, FixedBackOff.UNLIMITED_ATTEMPTS); }
From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java
/** * Specify the interval between recovery attempts, in <b>milliseconds</b>. * The default is 5000 ms, that is, 5 seconds. * @param recoveryInterval The recovery interval. */// w w w. j a v a 2s.c om public void setRecoveryInterval(long recoveryInterval) { this.recoveryBackOff = new FixedBackOff(recoveryInterval, FixedBackOff.UNLIMITED_ATTEMPTS); }
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 ww w .j a v a 2 s . co 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()); }
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 -> {// w w 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)); }