Add config prop for Rabbit's max inbound message body size

See gh-37603
pull/37626/head
Gary Russell 1 year ago committed by Andy Wilkinson
parent f9b4a1ea5b
commit 954f56287f

@ -133,6 +133,9 @@ public class RabbitConnectionFactoryBeanConfigurer {
.to(factory::setChannelRpcTimeout);
map.from(this.credentialsProvider).whenNonNull().to(factory::setCredentialsProvider);
map.from(this.credentialsRefreshService).whenNonNull().to(factory::setCredentialsRefreshService);
map.from(this.rabbitProperties.getMaxInboundMessageBodySize())
.whenNonNull()
.to((mimbs) -> factory.setMaxInboundMessageBodySize(Math.toIntExact(mimbs.toBytes())));
}
}

@ -31,6 +31,7 @@ import org.springframework.boot.context.properties.source.InvalidConfigurationPr
import org.springframework.boot.convert.DurationUnit;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.unit.DataSize;
/**
* Configuration properties for Rabbit.
@ -130,6 +131,11 @@ public class RabbitProperties {
*/
private Duration channelRpcTimeout = Duration.ofMinutes(10);
/**
* Maximum body size of inbound (received) messages in bytes.
*/
private DataSize maxInboundMessageBodySize;
/**
* Cache configuration.
*/
@ -360,6 +366,14 @@ public class RabbitProperties {
this.channelRpcTimeout = channelRpcTimeout;
}
public DataSize getMaxInboundMessageBodySize() {
return this.maxInboundMessageBodySize;
}
public void setMaxInboundMessageBodySize(DataSize maxInboundMessageBodySize) {
this.maxInboundMessageBodySize = maxInboundMessageBodySize;
}
public Cache getCache() {
return this.cache;
}

@ -150,6 +150,9 @@ class RabbitAutoConfigurationTests {
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
assertThat(rabbitConnectionFactory.getUsername()).isEqualTo(properties.getUsername());
assertThat(rabbitConnectionFactory.getPassword()).isEqualTo(properties.getPassword());
com.rabbitmq.client.ConnectionFactory defaultCf = new com.rabbitmq.client.ConnectionFactory();
assertThat(rabbitConnectionFactory).hasFieldOrPropertyWithValue("maxInboundMessageBodySize",
ReflectionTestUtils.getField(defaultCf, "maxInboundMessageBodySize"));
});
}
@ -160,7 +163,8 @@ class RabbitAutoConfigurationTests {
.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.channel-rpc-timeout:140")
"spring.rabbitmq.connection-timeout:123", "spring.rabbitmq.channel-rpc-timeout:140",
"spring.rabbitmq.max-inbound-message-body-size:128MB")
.run((context) -> {
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
@ -172,6 +176,7 @@ class RabbitAutoConfigurationTests {
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
assertThat(rcf.getChannelRpcTimeout()).isEqualTo(140);
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
assertThat(rcf).hasFieldOrPropertyWithValue("maxInboundMessageBodySize", 1024 * 1024 * 128);
});
}

Loading…
Cancel
Save