Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean(RabbitPropert
}
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

@pierre-sion pierre-sion Oct 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be annotate with @DurationUnit(ChronoUnit.MILLIS) (see field requestedHeartbeat)
The default duration is infinite, which may lead to a freeze of the Spring Boot application startup in some situations => may be a sensible default of 1 min would be wise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierre-sion the default is already ms so need to change the unit. In the original PR, no default value was set (null) and the mapping only applies if a non null value is provided. The default of 10 minutes is preserved but I've made that more explicit in a polish commit.


/**
* Cache configuration.
Expand Down Expand Up @@ -323,6 +328,10 @@ public void setPublisherReturns(boolean publisherReturns) {
public Duration getConnectionTimeout() {
return this.connectionTimeout;
}

public Duration getChannelRpcTimeout() {
return this.channelRpcTimeout;
}

public void setPublisherConfirmType(ConfirmType publisherConfirmType) {
this.publisherConfirmType = publisherConfirmType;
Expand All @@ -335,6 +344,10 @@ public ConfirmType getPublisherConfirmType() {
public void setConnectionTimeout(Duration connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}

public void setChannelRpcTimeout(Duration channelRpcTimeout) {
this.channelRpcTimeout = channelRpcTimeout;
}

public Cache getCache() {
return this.cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void testConnectionFactoryWithOverrides() {
.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");
Expand All @@ -150,6 +150,7 @@ void testConnectionFactoryWithOverrides() {
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);
});
}
Expand Down