Add configuration for RabbitMQ requested channel max property
See gh-19106
This commit is contained in:
parent
329352b865
commit
c043068578
|
|
@ -140,6 +140,7 @@ public class RabbitAutoConfiguration {
|
|||
}
|
||||
map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis)
|
||||
.to(factory::setConnectionTimeout);
|
||||
map.from(properties::getRequestedChannelMax).whenNonNull().to(factory::setRequestedChannelMax);
|
||||
factory.afterPropertiesSet();
|
||||
return factory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import org.springframework.util.StringUtils;
|
|||
* @author Josh Thornhill
|
||||
* @author Gary Russell
|
||||
* @author Artsiom Yudovin
|
||||
* @author Franjo Zilic
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.rabbitmq")
|
||||
|
|
@ -102,6 +103,13 @@ public class RabbitProperties {
|
|||
*/
|
||||
private Duration connectionTimeout;
|
||||
|
||||
/**
|
||||
* Requested Channel Max; zero for unlimited. Number of channels per connection client
|
||||
* will request from server, actual maximum will be negotiated between client and
|
||||
* server for lowest value (excluding zero as it represents unlimited).
|
||||
*/
|
||||
private Integer requestedChannelMax;
|
||||
|
||||
/**
|
||||
* Cache configuration.
|
||||
*/
|
||||
|
|
@ -310,6 +318,14 @@ public class RabbitProperties {
|
|||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public Integer getRequestedChannelMax() {
|
||||
return this.requestedChannelMax;
|
||||
}
|
||||
|
||||
public void setRequestedChannelMax(Integer requestedChannelMax) {
|
||||
this.requestedChannelMax = requestedChannelMax;
|
||||
}
|
||||
|
||||
public Cache getCache() {
|
||||
return this.cache;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ import static org.mockito.Mockito.verify;
|
|||
* @author Stephane Nicoll
|
||||
* @author Gary Russell
|
||||
* @author HaiTao Zhang
|
||||
* @author Franjo Zilic
|
||||
*/
|
||||
class RabbitAutoConfigurationTests {
|
||||
|
||||
|
|
@ -715,6 +716,24 @@ class RabbitAutoConfigurationTests {
|
|||
return (TrustManager) trustManager;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeDefaultRequestedChannelMax() throws Exception {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.rabbitmq.requestedChannelMax:12").run((context) -> {
|
||||
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
|
||||
assertThat(rabbitConnectionFactory.getRequestedChannelMax()).isEqualTo(12);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testKeepDefaultRequestedChannelMax() throws Exception {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
|
||||
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
|
||||
assertThat(rabbitConnectionFactory.getRequestedChannelMax())
|
||||
.isEqualTo(com.rabbitmq.client.ConnectionFactory.DEFAULT_CHANNEL_MAX);
|
||||
});
|
||||
}
|
||||
|
||||
private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) {
|
||||
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
||||
return connectionFactory.getRabbitConnectionFactory();
|
||||
|
|
|
|||
Loading…
Reference in New Issue