use of org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory in project spring-boot by spring-projects.
the class RabbitAutoConfigurationTests method testRabbitListenerContainerFactoryBackOff.
@Test
public void testRabbitListenerContainerFactoryBackOff() {
load(TestConfiguration5.class);
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
rabbitListenerContainerFactory.setTxSize(10);
verify(rabbitListenerContainerFactory).setTxSize(10);
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain");
assertThat(adviceChain).isNull();
}
use of org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory in project spring-boot by spring-projects.
the class RabbitAutoConfigurationTests method testRabbitListenerContainerFactoryWithCustomSettings.
@Test
public void testRabbitListenerContainerFactoryWithCustomSettings() {
load(new Class<?>[] { MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class }, "spring.rabbitmq.listener.retry.enabled:true", "spring.rabbitmq.listener.retry.maxAttempts:4", "spring.rabbitmq.listener.retry.initialInterval:2000", "spring.rabbitmq.listener.retry.multiplier:1.5", "spring.rabbitmq.listener.retry.maxInterval:5000", "spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.prefetch:40", "spring.rabbitmq.listener.defaultRequeueRejected:false", "spring.rabbitmq.listener.idleEventInterval:5", "spring.rabbitmq.listener.transactionSize:20");
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
assertThat(dfa.getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("acknowledgeMode")).isEqualTo(AcknowledgeMode.MANUAL);
assertThat(dfa.getPropertyValue("concurrentConsumers")).isEqualTo(5);
assertThat(dfa.getPropertyValue("maxConcurrentConsumers")).isEqualTo(10);
assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
assertThat(dfa.getPropertyValue("txSize")).isEqualTo(20);
assertThat(dfa.getPropertyValue("messageConverter")).isSameAs(this.context.getBean("myMessageConverter"));
assertThat(dfa.getPropertyValue("defaultRequeueRejected")).isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L);
Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain");
assertThat(adviceChain).isNotNull();
assertThat(adviceChain.length).isEqualTo(1);
dfa = new DirectFieldAccessor(adviceChain[0]);
MessageRecoverer messageRecoverer = this.context.getBean("myMessageRecoverer", MessageRecoverer.class);
MethodInvocationRecoverer<?> mir = (MethodInvocationRecoverer<?>) dfa.getPropertyValue("recoverer");
Message message = mock(Message.class);
Exception ex = new Exception("test");
mir.recover(new Object[] { "foo", message }, ex);
verify(messageRecoverer).recover(message, ex);
RetryTemplate retryTemplate = (RetryTemplate) dfa.getPropertyValue("retryOperations");
assertThat(retryTemplate).isNotNull();
dfa = new DirectFieldAccessor(retryTemplate);
SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) dfa.getPropertyValue("retryPolicy");
ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) dfa.getPropertyValue("backOffPolicy");
assertThat(retryPolicy.getMaxAttempts()).isEqualTo(4);
assertThat(backOffPolicy.getInitialInterval()).isEqualTo(2000);
assertThat(backOffPolicy.getMultiplier()).isEqualTo(1.5);
assertThat(backOffPolicy.getMaxInterval()).isEqualTo(5000);
}
use of org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory in project spring-boot by spring-projects.
the class RabbitAnnotationDrivenConfiguration method rabbitListenerContainerFactory.
@Bean
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
configurer.configure(factory, connectionFactory);
return factory;
}
Aggregations