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

See gh-37603
pull/37626/head
Andy Wilkinson 1 year ago
parent 954f56287f
commit 4e5f16f2bc

@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.amqp.RabbitConnectionDetails.Addre
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.springframework.util.unit.DataSize;
/**
* Configures {@link RabbitConnectionFactoryBean} with sensible defaults.
@ -135,7 +136,8 @@ public class RabbitConnectionFactoryBeanConfigurer {
map.from(this.credentialsRefreshService).whenNonNull().to(factory::setCredentialsRefreshService);
map.from(this.rabbitProperties.getMaxInboundMessageBodySize())
.whenNonNull()
.to((mimbs) -> factory.setMaxInboundMessageBodySize(Math.toIntExact(mimbs.toBytes())));
.asInt(DataSize::toBytes)
.to(factory::setMaxInboundMessageBodySize);
}
}

@ -132,9 +132,9 @@ public class RabbitProperties {
private Duration channelRpcTimeout = Duration.ofMinutes(10);
/**
* Maximum body size of inbound (received) messages in bytes.
* Maximum size of the body of inbound (received) messages.
*/
private DataSize maxInboundMessageBodySize;
private DataSize maxInboundMessageBodySize = DataSize.ofMegabytes(64);
/**
* Cache configuration.

@ -150,9 +150,8 @@ 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"));
assertThat(rabbitConnectionFactory).extracting("maxInboundMessageBodySize")
.isEqualTo((int) properties.getMaxInboundMessageBodySize().toBytes());
});
}

Loading…
Cancel
Save