Browse Source

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

See gh-37603
pull/37626/head
Andy Wilkinson 2 years ago
parent
commit
4e5f16f2bc
  1. 4
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitConnectionFactoryBeanConfigurer.java
  2. 4
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
  3. 5
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

4
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitConnectionFactoryBeanConfigurer.java

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

4
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

@ -132,9 +132,9 @@ public class RabbitProperties {
private Duration channelRpcTimeout = Duration.ofMinutes(10); 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. * Cache configuration.

5
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

@ -150,9 +150,8 @@ class RabbitAutoConfigurationTests {
com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context); com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context);
assertThat(rabbitConnectionFactory.getUsername()).isEqualTo(properties.getUsername()); assertThat(rabbitConnectionFactory.getUsername()).isEqualTo(properties.getUsername());
assertThat(rabbitConnectionFactory.getPassword()).isEqualTo(properties.getPassword()); assertThat(rabbitConnectionFactory.getPassword()).isEqualTo(properties.getPassword());
com.rabbitmq.client.ConnectionFactory defaultCf = new com.rabbitmq.client.ConnectionFactory(); assertThat(rabbitConnectionFactory).extracting("maxInboundMessageBodySize")
assertThat(rabbitConnectionFactory).hasFieldOrPropertyWithValue("maxInboundMessageBodySize", .isEqualTo((int) properties.getMaxInboundMessageBodySize().toBytes());
ReflectionTestUtils.getField(defaultCf, "maxInboundMessageBodySize"));
}); });
} }

Loading…
Cancel
Save