Polish "Add configuration for RabbitMQ requested channel max property"

See gh-19106
pull/19159/head
Stephane Nicoll 5 years ago
parent c043068578
commit d2f256abe8

@ -124,6 +124,7 @@ public class RabbitAutoConfiguration {
map.from(properties::determineVirtualHost).whenNonNull().to(factory::setVirtualHost); map.from(properties::determineVirtualHost).whenNonNull().to(factory::setVirtualHost);
map.from(properties::getRequestedHeartbeat).whenNonNull().asInt(Duration::getSeconds) map.from(properties::getRequestedHeartbeat).whenNonNull().asInt(Duration::getSeconds)
.to(factory::setRequestedHeartbeat); .to(factory::setRequestedHeartbeat);
map.from(properties::getRequestedChannelMax).to(factory::setRequestedChannelMax);
RabbitProperties.Ssl ssl = properties.getSsl(); RabbitProperties.Ssl ssl = properties.getSsl();
if (ssl.determineEnabled()) { if (ssl.determineEnabled()) {
factory.setUseSSL(true); factory.setUseSSL(true);
@ -140,7 +141,6 @@ public class RabbitAutoConfiguration {
} }
map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis) map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis)
.to(factory::setConnectionTimeout); .to(factory::setConnectionTimeout);
map.from(properties::getRequestedChannelMax).whenNonNull().to(factory::setRequestedChannelMax);
factory.afterPropertiesSet(); factory.afterPropertiesSet();
return factory; return factory;
} }

@ -88,6 +88,11 @@ public class RabbitProperties {
@DurationUnit(ChronoUnit.SECONDS) @DurationUnit(ChronoUnit.SECONDS)
private Duration requestedHeartbeat; private Duration requestedHeartbeat;
/**
* Number of channels per connection requested by the client. Use 0 for unlimited.
*/
private int requestedChannelMax = 2047;
/** /**
* Whether to enable publisher returns. * Whether to enable publisher returns.
*/ */
@ -103,13 +108,6 @@ public class RabbitProperties {
*/ */
private Duration connectionTimeout; 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. * Cache configuration.
*/ */
@ -283,6 +281,14 @@ public class RabbitProperties {
this.requestedHeartbeat = requestedHeartbeat; this.requestedHeartbeat = requestedHeartbeat;
} }
public int getRequestedChannelMax() {
return this.requestedChannelMax;
}
public void setRequestedChannelMax(int requestedChannelMax) {
this.requestedChannelMax = requestedChannelMax;
}
@DeprecatedConfigurationProperty(reason = "replaced to support additional confirm types", @DeprecatedConfigurationProperty(reason = "replaced to support additional confirm types",
replacement = "spring.rabbitmq.publisher-confirm-type") replacement = "spring.rabbitmq.publisher-confirm-type")
public boolean isPublisherConfirms() { public boolean isPublisherConfirms() {
@ -318,14 +324,6 @@ public class RabbitProperties {
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;
} }
public Integer getRequestedChannelMax() {
return this.requestedChannelMax;
}
public void setRequestedChannelMax(Integer requestedChannelMax) {
this.requestedChannelMax = requestedChannelMax;
}
public Cache getCache() { public Cache getCache() {
return this.cache; return this.cache;
} }

@ -100,6 +100,8 @@ class RabbitAutoConfigurationTests {
assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate); assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
assertThat(amqpAdmin).isNotNull(); assertThat(amqpAdmin).isNotNull();
assertThat(connectionFactory.getHost()).isEqualTo("localhost"); assertThat(connectionFactory.getHost()).isEqualTo("localhost");
assertThat(getTargetConnectionFactory(context).getRequestedChannelMax())
.isEqualTo(com.rabbitmq.client.ConnectionFactory.DEFAULT_CHANNEL_MAX);
assertThat(connectionFactory.isPublisherConfirms()).isFalse(); assertThat(connectionFactory.isPublisherConfirms()).isFalse();
assertThat(connectionFactory.isPublisherReturns()).isFalse(); assertThat(connectionFactory.isPublisherReturns()).isFalse();
assertThat(context.containsBean("rabbitListenerContainerFactory")) assertThat(context.containsBean("rabbitListenerContainerFactory"))
@ -601,6 +603,15 @@ class RabbitAutoConfigurationTests {
}); });
} }
@Test
void customizeRequestedChannelMax() {
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 @Test
void noSslByDefault() { void noSslByDefault() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
@ -716,24 +727,6 @@ class RabbitAutoConfigurationTests {
return (TrustManager) trustManager; 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) { private com.rabbitmq.client.ConnectionFactory getTargetConnectionFactory(AssertableApplicationContext context) {
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class); CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
return connectionFactory.getRabbitConnectionFactory(); return connectionFactory.getRabbitConnectionFactory();

Loading…
Cancel
Save