Search in sources :

Example 1 with RabbitTemplate

use of org.springframework.amqp.rabbit.core.RabbitTemplate in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitTemplateRetry.

@Test
public void testRabbitTemplateRetry() {
    load(TestConfiguration.class, "spring.rabbitmq.template.retry.enabled:true", "spring.rabbitmq.template.retry.maxAttempts:4", "spring.rabbitmq.template.retry.initialInterval:2000", "spring.rabbitmq.template.retry.multiplier:1.5", "spring.rabbitmq.template.retry.maxInterval:5000", "spring.rabbitmq.template.receiveTimeout:123", "spring.rabbitmq.template.replyTimeout:456");
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitTemplate);
    assertThat(dfa.getPropertyValue("receiveTimeout")).isEqualTo(123L);
    assertThat(dfa.getPropertyValue("replyTimeout")).isEqualTo(456L);
    RetryTemplate retryTemplate = (RetryTemplate) dfa.getPropertyValue("retryTemplate");
    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);
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) RetryTemplate(org.springframework.retry.support.RetryTemplate) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) Test(org.junit.Test)

Example 2 with RabbitTemplate

use of org.springframework.amqp.rabbit.core.RabbitTemplate in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitTemplateBackOff.

@Test
public void testRabbitTemplateBackOff() {
    load(TestConfiguration3.class);
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    assertThat(rabbitTemplate.getMessageConverter()).isEqualTo(this.context.getBean("testMessageConverter"));
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) Test(org.junit.Test)

Example 3 with RabbitTemplate

use of org.springframework.amqp.rabbit.core.RabbitTemplate in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testConnectionFactoryBackOff.

@Test
public void testConnectionFactoryBackOff() {
    load(TestConfiguration2.class);
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    assertThat(connectionFactory).isEqualTo(rabbitTemplate.getConnectionFactory());
    assertThat(connectionFactory.getHost()).isEqualTo("otherserver");
    assertThat(connectionFactory.getPort()).isEqualTo(8001);
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Example 4 with RabbitTemplate

use of org.springframework.amqp.rabbit.core.RabbitTemplate in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitTemplateMandatoryDisabledEvenIfPublisherReturnsIsSet.

@Test
public void testRabbitTemplateMandatoryDisabledEvenIfPublisherReturnsIsSet() {
    load(TestConfiguration.class, "spring.rabbitmq.template.mandatory:false", "spring.rabbitmq.publisher-returns=true");
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    assertThat(getMandatory(rabbitTemplate)).isFalse();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) Test(org.junit.Test)

Example 5 with RabbitTemplate

use of org.springframework.amqp.rabbit.core.RabbitTemplate in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitTemplateMandatory.

@Test
public void testRabbitTemplateMandatory() {
    load(TestConfiguration.class, "spring.rabbitmq.template.mandatory:true");
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    assertThat(getMandatory(rabbitTemplate)).isTrue();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) Test(org.junit.Test)

Aggregations

RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)14 Test (org.junit.Test)8 Bean (org.springframework.context.annotation.Bean)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)3 RabbitAdmin (org.springframework.amqp.rabbit.core.RabbitAdmin)1 RabbitMessagingTemplate (org.springframework.amqp.rabbit.core.RabbitMessagingTemplate)1 ExponentialBackOffPolicy (org.springframework.retry.backoff.ExponentialBackOffPolicy)1 SimpleRetryPolicy (org.springframework.retry.policy.SimpleRetryPolicy)1 RetryTemplate (org.springframework.retry.support.RetryTemplate)1