Merge pull request #19106 from fzilic

* pr/19106:
  Polish "Add configuration for RabbitMQ requested channel max property"
  Add configuration for RabbitMQ requested channel max property

Closes gh-19106
pull/19159/head
Stephane Nicoll 5 years ago
commit 526dac2dee

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

@ -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")
@ -87,6 +88,11 @@ public class RabbitProperties {
@DurationUnit(ChronoUnit.SECONDS)
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.
*/
@ -275,6 +281,14 @@ public class RabbitProperties {
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",
replacement = "spring.rabbitmq.publisher-confirm-type")
public boolean isPublisherConfirms() {

@ -81,6 +81,7 @@ import static org.mockito.Mockito.verify;
* @author Stephane Nicoll
* @author Gary Russell
* @author HaiTao Zhang
* @author Franjo Zilic
*/
class RabbitAutoConfigurationTests {
@ -99,6 +100,8 @@ class RabbitAutoConfigurationTests {
assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
assertThat(amqpAdmin).isNotNull();
assertThat(connectionFactory.getHost()).isEqualTo("localhost");
assertThat(getTargetConnectionFactory(context).getRequestedChannelMax())
.isEqualTo(com.rabbitmq.client.ConnectionFactory.DEFAULT_CHANNEL_MAX);
assertThat(connectionFactory.isPublisherConfirms()).isFalse();
assertThat(connectionFactory.isPublisherReturns()).isFalse();
assertThat(context.containsBean("rabbitListenerContainerFactory"))
@ -600,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
void noSslByDefault() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {

Loading…
Cancel
Save