Skip to content

Commit baa9d12

Browse files
jkhowardsnicoll
authored andcommitted
Add configuration option for channelRpcTimeout
This commit adds a configuration option to configure RabbitConnectionFactory's channelRpcTimeout property. See gh-23564
1 parent 341bccb commit baa9d12

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean(RabbitPropert
149149
}
150150
map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis)
151151
.to(factory::setConnectionTimeout);
152+
map.from(properties::getChannelRpcTimeout).whenNonNull().asInt(Duration::toMillis)
153+
.to(factory::setChannelRpcTimeout);
152154
map.from(credentialsProvider::getIfUnique).whenNonNull().to(factory::setCredentialsProvider);
153155
map.from(credentialsRefreshService::getIfUnique).whenNonNull().to(factory::setCredentialsRefreshService);
154156
factory.afterPropertiesSet();

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ public class RabbitProperties {
119119
* Connection timeout. Set it to zero to wait forever.
120120
*/
121121
private Duration connectionTimeout;
122+
123+
/**
124+
* Channel RPC timeout.
125+
*/
126+
private Duration channelRpcTimeout;
122127

123128
/**
124129
* Cache configuration.
@@ -323,6 +328,10 @@ public void setPublisherReturns(boolean publisherReturns) {
323328
public Duration getConnectionTimeout() {
324329
return this.connectionTimeout;
325330
}
331+
332+
public Duration getChannelRpcTimeout() {
333+
return this.channelRpcTimeout;
334+
}
326335

327336
public void setPublisherConfirmType(ConfirmType publisherConfirmType) {
328337
this.publisherConfirmType = publisherConfirmType;
@@ -335,6 +344,10 @@ public ConfirmType getPublisherConfirmType() {
335344
public void setConnectionTimeout(Duration connectionTimeout) {
336345
this.connectionTimeout = connectionTimeout;
337346
}
347+
348+
public void setChannelRpcTimeout(Duration channelRpcTimeout) {
349+
this.channelRpcTimeout = channelRpcTimeout;
350+
}
338351

339352
public Cache getCache() {
340353
return this.cache;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void testConnectionFactoryWithOverrides() {
140140
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
141141
"spring.rabbitmq.address-shuffle-mode=random", "spring.rabbitmq.username:alice",
142142
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
143-
"spring.rabbitmq.connection-timeout:123")
143+
"spring.rabbitmq.connection-timeout:123", "spring.rabbitmq.channel-rpc-timeout:140")
144144
.run((context) -> {
145145
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
146146
assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
@@ -150,6 +150,7 @@ void testConnectionFactoryWithOverrides() {
150150
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
151151
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
152152
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
153+
assertThat(rcf.getChannelRpcTimeout()).isEqualTo(140);
153154
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
154155
});
155156
}

0 commit comments

Comments
 (0)