Skip to content

Commit a18470d

Browse files
authored
GH-2495: Add maxInboundMessageBodySize to RCFB
Resolves #2495 Although the factory bean has... ```java /** * Access the connection factory to set any other properties not supported by * this factory bean. * @return the connection factory. * @SInCE 1.7.14 */ public ConnectionFactory getRabbitConnectionFactory() { ``` ...this new CF property could be a breaking change for users that configure the factory bean using XML. **cherry-pick to 2.4.x**
1 parent 3675a6c commit a18470d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/RabbitConnectionFactoryBean.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@
6666
* using the supplied properties and intializes key and trust manager factories, using
6767
* algorithm {@code SunX509} by default. These are then used to initialize an
6868
* {@link SSLContext} using the {@link #setSslAlgorithm(String) sslAlgorithm} (default
69-
* TLSv1.1).
69+
* TLSv1.2, falling back to TLSv1.1, if 1.2 is not available).
7070
* <p>
7171
* Override {@link #createSSLContext()} to create and/or perform further modification of
7272
* the context.
@@ -672,6 +672,16 @@ public void setEnableHostnameVerification(boolean enable) {
672672
this.enableHostnameVerification = enable;
673673
}
674674

675+
/**
676+
* Set the maximum body size of inbound (received) messages in bytes.
677+
* @param maxInboundMessageBodySize the maximum size.
678+
* @since 2.4.15
679+
* @see com.rabbitmq.client.ConnectionFactory#setMaxInboundMessageBodySize(int)
680+
*/
681+
public void setMaxInboundMessageBodySize(int maxInboundMessageBodySize) {
682+
this.connectionFactory.setMaxInboundMessageBodySize(maxInboundMessageBodySize);
683+
}
684+
675685
protected String getKeyStoreAlgorithm() {
676686
return this.keyStoreAlgorithm;
677687
}

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/SSLConnectionTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,13 +76,15 @@ public void test() throws Exception {
7676
@Test
7777
public void testAlgNoProps() throws Exception {
7878
RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
79+
fb.setMaxInboundMessageBodySize(1000);
7980
ConnectionFactory rabbitCf = spy(TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
8081
new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
8182
fb.setUseSSL(true);
8283
fb.setSslAlgorithm("TLSv1.2");
8384
fb.afterPropertiesSet();
8485
fb.getObject();
8586
verify(rabbitCf).useSslProtocol(Mockito.any(SSLContext.class));
87+
assertThat(rabbitCf).hasFieldOrPropertyWithValue("maxInboundMessageBodySize", 1000);
8688
}
8789

8890
@Test

0 commit comments

Comments
 (0)