Search in sources :

Example 1 with CachingConnectionFactory

use of org.springframework.amqp.rabbit.connection.CachingConnectionFactory in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testConnectionFactoryVirtualHostMultiLeadingSlashes.

@Test
public void testConnectionFactoryVirtualHostMultiLeadingSlashes() {
    load(TestConfiguration.class, "spring.rabbitmq.virtual_host:///foo");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    assertThat(connectionFactory.getVirtualHost()).isEqualTo("///foo");
}
Also used : CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Example 2 with CachingConnectionFactory

use of org.springframework.amqp.rabbit.connection.CachingConnectionFactory in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testConnectionFactoryCacheSettings.

@Test
public void testConnectionFactoryCacheSettings() {
    load(TestConfiguration.class, "spring.rabbitmq.cache.channel.size=23", "spring.rabbitmq.cache.channel.checkoutTimeout=1000", "spring.rabbitmq.cache.connection.mode=CONNECTION", "spring.rabbitmq.cache.connection.size=2");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    assertThat(dfa.getPropertyValue("channelCacheSize")).isEqualTo(23);
    assertThat(dfa.getPropertyValue("cacheMode")).isEqualTo(CacheMode.CONNECTION);
    assertThat(dfa.getPropertyValue("connectionCacheSize")).isEqualTo(2);
    assertThat(dfa.getPropertyValue("channelCheckoutTimeout")).isEqualTo(1000L);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Example 3 with CachingConnectionFactory

use of org.springframework.amqp.rabbit.connection.CachingConnectionFactory in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testConnectionFactoryVirtualHostNoLeadingSlash.

@Test
public void testConnectionFactoryVirtualHostNoLeadingSlash() {
    load(TestConfiguration.class, "spring.rabbitmq.virtual_host:foo");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    assertThat(connectionFactory.getVirtualHost()).isEqualTo("foo");
}
Also used : CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Example 4 with CachingConnectionFactory

use of org.springframework.amqp.rabbit.connection.CachingConnectionFactory 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 5 with CachingConnectionFactory

use of org.springframework.amqp.rabbit.connection.CachingConnectionFactory in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testConnectionFactoryWithOverrides.

@Test
public void testConnectionFactoryWithOverrides() {
    load(TestConfiguration.class, "spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost", "spring.rabbitmq.connection-timeout:123");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
    assertThat(connectionFactory.getPort()).isEqualTo(9000);
    assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    com.rabbitmq.client.ConnectionFactory rcf = (com.rabbitmq.client.ConnectionFactory) dfa.getPropertyValue("rabbitConnectionFactory");
    assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
    assertThat((Address[]) dfa.getPropertyValue("addresses")).hasSize(1);
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Aggregations

CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)15 Test (org.junit.Test)9 Bean (org.springframework.context.annotation.Bean)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)3 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)1 RabbitAdmin (org.springframework.amqp.rabbit.core.RabbitAdmin)1 RabbitMessagingTemplate (org.springframework.amqp.rabbit.core.RabbitMessagingTemplate)1