Skip to content

Commit 2ab2cf0

Browse files
committed
Merge pull request #23564 from jkhoward
* pr/23564: Polish "Add configuration option for channelRpcTimeout" Add configuration option for channelRpcTimeout Closes gh-23564
2 parents 341bccb + c4e1b4f commit 2ab2cf0

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-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
@@ -120,6 +120,11 @@ public class RabbitProperties {
120120
*/
121121
private Duration connectionTimeout;
122122

123+
/**
124+
* Continuation timeout for RPC calls in channels. Set it to zero to wait forever.
125+
*/
126+
private Duration channelRpcTimeout = Duration.ofMinutes(10);
127+
123128
/**
124129
* Cache configuration.
125130
*/
@@ -336,6 +341,14 @@ public void setConnectionTimeout(Duration connectionTimeout) {
336341
this.connectionTimeout = connectionTimeout;
337342
}
338343

344+
public Duration getChannelRpcTimeout() {
345+
return this.channelRpcTimeout;
346+
}
347+
348+
public void setChannelRpcTimeout(Duration channelRpcTimeout) {
349+
this.channelRpcTimeout = channelRpcTimeout;
350+
}
351+
339352
public Cache getCache() {
340353
return this.cache;
341354
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void testDefaultRabbitConfiguration() {
108108
.isEqualTo(com.rabbitmq.client.ConnectionFactory.DEFAULT_CHANNEL_MAX);
109109
assertThat(connectionFactory.isPublisherConfirms()).isFalse();
110110
assertThat(connectionFactory.isPublisherReturns()).isFalse();
111+
assertThat(connectionFactory.getRabbitConnectionFactory().getChannelRpcTimeout())
112+
.isEqualTo(com.rabbitmq.client.ConnectionFactory.DEFAULT_CHANNEL_RPC_TIMEOUT);
111113
assertThat(context.containsBean("rabbitListenerContainerFactory"))
112114
.as("Listener container factory should be created by default").isTrue();
113115
});
@@ -140,7 +142,7 @@ void testConnectionFactoryWithOverrides() {
140142
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
141143
"spring.rabbitmq.address-shuffle-mode=random", "spring.rabbitmq.username:alice",
142144
"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
143-
"spring.rabbitmq.connection-timeout:123")
145+
"spring.rabbitmq.connection-timeout:123", "spring.rabbitmq.channel-rpc-timeout:140")
144146
.run((context) -> {
145147
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
146148
assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
@@ -150,6 +152,7 @@ void testConnectionFactoryWithOverrides() {
150152
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
151153
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
152154
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
155+
assertThat(rcf.getChannelRpcTimeout()).isEqualTo(140);
153156
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
154157
});
155158
}

0 commit comments

Comments
 (0)