Add configuration option for channelRpcTimeout

This commit adds a configuration option to configure
RabbitConnectionFactory's channelRpcTimeout property.

See gh-23564
This commit is contained in:
Jasmine Howard 2020-10-01 17:52:21 -04:00 committed by Stephane Nicoll
parent 341bccbdd7
commit baa9d129f2
3 changed files with 17 additions and 1 deletions

View File

@ -149,6 +149,8 @@ public class RabbitAutoConfiguration {
}
map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis)
.to(factory::setConnectionTimeout);
map.from(properties::getChannelRpcTimeout).whenNonNull().asInt(Duration::toMillis)
.to(factory::setChannelRpcTimeout);
map.from(credentialsProvider::getIfUnique).whenNonNull().to(factory::setCredentialsProvider);
map.from(credentialsRefreshService::getIfUnique).whenNonNull().to(factory::setCredentialsRefreshService);
factory.afterPropertiesSet();

View File

@ -119,6 +119,11 @@ public class RabbitProperties {
* Connection timeout. Set it to zero to wait forever.
*/
private Duration connectionTimeout;
/**
* Channel RPC timeout.
*/
private Duration channelRpcTimeout;
/**
* Cache configuration.
@ -323,6 +328,10 @@ public class RabbitProperties {
public Duration getConnectionTimeout() {
return this.connectionTimeout;
}
public Duration getChannelRpcTimeout() {
return this.channelRpcTimeout;
}
public void setPublisherConfirmType(ConfirmType publisherConfirmType) {
this.publisherConfirmType = publisherConfirmType;
@ -335,6 +344,10 @@ public class RabbitProperties {
public void setConnectionTimeout(Duration connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
public void setChannelRpcTimeout(Duration channelRpcTimeout) {
this.channelRpcTimeout = channelRpcTimeout;
}
public Cache getCache() {
return this.cache;

View File

@ -140,7 +140,7 @@ class RabbitAutoConfigurationTests {
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
"spring.rabbitmq.address-shuffle-mode=random", "spring.rabbitmq.username:alice",
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
"spring.rabbitmq.connection-timeout:123")
"spring.rabbitmq.connection-timeout:123", "spring.rabbitmq.channel-rpc-timeout:140")
.run((context) -> {
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
@ -150,6 +150,7 @@ class RabbitAutoConfigurationTests {
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
assertThat(rcf.getChannelRpcTimeout()).isEqualTo(140);
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
});
}