Add RabbitMQ Connection Timeout Property

Fixes gh-685
Closes gh-5791
pull/5788/merge
Gary Russell 9 years ago committed by Phillip Webb
parent 719a57dcfa
commit 12b9f0262b

@ -114,6 +114,9 @@ public class RabbitAutoConfiguration {
factory.setTrustStore(ssl.getTrustStore()); factory.setTrustStore(ssl.getTrustStore());
factory.setTrustStorePassphrase(ssl.getTrustStorePassword()); factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
} }
if (config.getConnectionTimeout() != null) {
factory.setConnectionTimeout(config.getConnectionTimeout());
}
factory.afterPropertiesSet(); factory.afterPropertiesSet();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory( CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
factory.getObject()); factory.getObject());

@ -88,6 +88,11 @@ public class RabbitProperties {
*/ */
private boolean publisherReturns; private boolean publisherReturns;
/**
* The connection timeout, in milliseconds; zero for infinite.
*/
private Integer connectionTimeout;
/** /**
* Cache configuration. * Cache configuration.
*/ */
@ -222,6 +227,14 @@ public class RabbitProperties {
this.publisherReturns = publisherReturns; this.publisherReturns = publisherReturns;
} }
public Integer getConnectionTimeout() {
return this.connectionTimeout;
}
public void setConnectionTimeout(Integer connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
public Cache getCache() { public Cache getCache() {
return this.cache; return this.cache;
} }

@ -101,12 +101,17 @@ public class RabbitAutoConfigurationTests {
public void testConnectionFactoryWithOverrides() { public void testConnectionFactoryWithOverrides() {
load(TestConfiguration.class, "spring.rabbitmq.host:remote-server", load(TestConfiguration.class, "spring.rabbitmq.host:remote-server",
"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", "spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost"); "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
"spring.rabbitmq.connection-timeout:123");
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getHost()).isEqualTo("remote-server"); assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
assertThat(connectionFactory.getPort()).isEqualTo(9000); assertThat(connectionFactory.getPort()).isEqualTo(9000);
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost"); 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);
} }
@Test @Test

@ -841,6 +841,7 @@ content into your application; rather pick only the properties that you need.
spring.rabbitmq.cache.channel.size= # Number of channels to retain in the cache. spring.rabbitmq.cache.channel.size= # Number of channels to retain in the cache.
spring.rabbitmq.cache.connection.mode=CHANNEL # Connection factory cache mode. spring.rabbitmq.cache.connection.mode=CHANNEL # Connection factory cache mode.
spring.rabbitmq.cache.connection.size= # Number of connections to cache. spring.rabbitmq.cache.connection.size= # Number of connections to cache.
spring.rabbitmq.connection-timeout= # Connection Timeout, in milliseconds.
spring.rabbitmq.dynamic=true # Create an AmqpAdmin bean. spring.rabbitmq.dynamic=true # Create an AmqpAdmin bean.
spring.rabbitmq.host=localhost # RabbitMQ host. spring.rabbitmq.host=localhost # RabbitMQ host.
spring.rabbitmq.listener.acknowledge-mode= # Acknowledge mode of container. spring.rabbitmq.listener.acknowledge-mode= # Acknowledge mode of container.

Loading…
Cancel
Save