|
1 |
| -// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. |
| 1 | +// Copyright (c) 2007-2023 VMware, Inc. or its affiliates. All rights reserved. |
2 | 2 | //
|
3 | 3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
|
4 | 4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
|
@@ -205,6 +205,13 @@ public class ConnectionFactory implements Cloneable {
|
205 | 205 |
|
206 | 206 | private CredentialsRefreshService credentialsRefreshService;
|
207 | 207 |
|
| 208 | + /** |
| 209 | + * Maximum body size of inbound (received) messages in bytes. |
| 210 | + * |
| 211 | + * <p>Default value is 67,108,864 (64 MiB). |
| 212 | + */ |
| 213 | + private int maxInboundMessageBodySize = 1_048_576 * 64; |
| 214 | + |
208 | 215 | /** @return the default host to use for connections */
|
209 | 216 | public String getHost() {
|
210 | 217 | return host;
|
@@ -970,11 +977,15 @@ protected synchronized FrameHandlerFactory createFrameHandlerFactory() throws IO
|
970 | 977 | if(this.nioParams.getNioExecutor() == null && this.nioParams.getThreadFactory() == null) {
|
971 | 978 | this.nioParams.setThreadFactory(getThreadFactory());
|
972 | 979 | }
|
973 |
| - this.frameHandlerFactory = new SocketChannelFrameHandlerFactory(connectionTimeout, nioParams, isSSL(), sslContextFactory); |
| 980 | + this.frameHandlerFactory = new SocketChannelFrameHandlerFactory( |
| 981 | + connectionTimeout, nioParams, isSSL(), sslContextFactory, |
| 982 | + this.maxInboundMessageBodySize); |
974 | 983 | }
|
975 | 984 | return this.frameHandlerFactory;
|
976 | 985 | } else {
|
977 |
| - return new SocketFrameHandlerFactory(connectionTimeout, socketFactory, socketConf, isSSL(), this.shutdownExecutor, sslContextFactory); |
| 986 | + return new SocketFrameHandlerFactory(connectionTimeout, socketFactory, |
| 987 | + socketConf, isSSL(), this.shutdownExecutor, sslContextFactory, |
| 988 | + this.maxInboundMessageBodySize); |
978 | 989 | }
|
979 | 990 |
|
980 | 991 | }
|
@@ -1273,6 +1284,7 @@ public ConnectionParams params(ExecutorService consumerWorkServiceExecutor) {
|
1273 | 1284 | result.setRecoveredQueueNameSupplier(recoveredQueueNameSupplier);
|
1274 | 1285 | result.setTrafficListener(trafficListener);
|
1275 | 1286 | result.setCredentialsRefreshService(credentialsRefreshService);
|
| 1287 | + result.setMaxInboundMessageBodySize(maxInboundMessageBodySize); |
1276 | 1288 | return result;
|
1277 | 1289 | }
|
1278 | 1290 |
|
@@ -1556,6 +1568,21 @@ public int getChannelRpcTimeout() {
|
1556 | 1568 | return channelRpcTimeout;
|
1557 | 1569 | }
|
1558 | 1570 |
|
| 1571 | + /** |
| 1572 | + * Maximum body size of inbound (received) messages in bytes. |
| 1573 | + * |
| 1574 | + * <p>Default value is 67,108,864 (64 MiB). |
| 1575 | + * |
| 1576 | + * @param maxInboundMessageBodySize the maximum size of inbound messages |
| 1577 | + */ |
| 1578 | + public void setMaxInboundMessageBodySize(int maxInboundMessageBodySize) { |
| 1579 | + if (maxInboundMessageBodySize <= 0) { |
| 1580 | + throw new IllegalArgumentException("Max inbound message body size must be greater than 0: " |
| 1581 | + + maxInboundMessageBodySize); |
| 1582 | + } |
| 1583 | + this.maxInboundMessageBodySize = maxInboundMessageBodySize; |
| 1584 | + } |
| 1585 | + |
1559 | 1586 | /**
|
1560 | 1587 | * The factory to create SSL contexts.
|
1561 | 1588 | * This provides more flexibility to create {@link SSLContext}s
|
|
0 commit comments