|
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
|
@@ -203,6 +203,13 @@ public class ConnectionFactory implements Cloneable {
|
203 | 203 |
|
204 | 204 | private CredentialsRefreshService credentialsRefreshService;
|
205 | 205 |
|
| 206 | + /** |
| 207 | + * Maximum body size of inbound (received) messages in bytes. |
| 208 | + * |
| 209 | + * <p>Default value is 67,108,864 (64 MiB). |
| 210 | + */ |
| 211 | + private int maxInboundMessageBodySize = 1_048_576 * 64; |
| 212 | + |
206 | 213 | /** @return the default host to use for connections */
|
207 | 214 | public String getHost() {
|
208 | 215 | return host;
|
@@ -997,11 +1004,15 @@ protected synchronized FrameHandlerFactory createFrameHandlerFactory() throws IO
|
997 | 1004 | if(this.nioParams.getNioExecutor() == null && this.nioParams.getThreadFactory() == null) {
|
998 | 1005 | this.nioParams.setThreadFactory(getThreadFactory());
|
999 | 1006 | }
|
1000 |
| - this.frameHandlerFactory = new SocketChannelFrameHandlerFactory(connectionTimeout, nioParams, isSSL(), sslContextFactory); |
| 1007 | + this.frameHandlerFactory = new SocketChannelFrameHandlerFactory( |
| 1008 | + connectionTimeout, nioParams, isSSL(), sslContextFactory, |
| 1009 | + this.maxInboundMessageBodySize); |
1001 | 1010 | }
|
1002 | 1011 | return this.frameHandlerFactory;
|
1003 | 1012 | } else {
|
1004 |
| - return new SocketFrameHandlerFactory(connectionTimeout, socketFactory, socketConf, isSSL(), this.shutdownExecutor, sslContextFactory); |
| 1013 | + return new SocketFrameHandlerFactory(connectionTimeout, socketFactory, |
| 1014 | + socketConf, isSSL(), this.shutdownExecutor, sslContextFactory, |
| 1015 | + this.maxInboundMessageBodySize); |
1005 | 1016 | }
|
1006 | 1017 |
|
1007 | 1018 | }
|
@@ -1300,6 +1311,7 @@ public ConnectionParams params(ExecutorService consumerWorkServiceExecutor) {
|
1300 | 1311 | result.setRecoveredQueueNameSupplier(recoveredQueueNameSupplier);
|
1301 | 1312 | result.setTrafficListener(trafficListener);
|
1302 | 1313 | result.setCredentialsRefreshService(credentialsRefreshService);
|
| 1314 | + result.setMaxInboundMessageBodySize(maxInboundMessageBodySize); |
1303 | 1315 | return result;
|
1304 | 1316 | }
|
1305 | 1317 |
|
@@ -1590,6 +1602,21 @@ public int getChannelRpcTimeout() {
|
1590 | 1602 | return channelRpcTimeout;
|
1591 | 1603 | }
|
1592 | 1604 |
|
| 1605 | + /** |
| 1606 | + * Maximum body size of inbound (received) messages in bytes. |
| 1607 | + * |
| 1608 | + * <p>Default value is 67,108,864 (64 MiB). |
| 1609 | + * |
| 1610 | + * @param maxInboundMessageBodySize the maximum size of inbound messages |
| 1611 | + */ |
| 1612 | + public void setMaxInboundMessageBodySize(int maxInboundMessageBodySize) { |
| 1613 | + if (maxInboundMessageBodySize <= 0) { |
| 1614 | + throw new IllegalArgumentException("Max inbound message body size must be greater than 0: " |
| 1615 | + + maxInboundMessageBodySize); |
| 1616 | + } |
| 1617 | + this.maxInboundMessageBodySize = maxInboundMessageBodySize; |
| 1618 | + } |
| 1619 | + |
1593 | 1620 | /**
|
1594 | 1621 | * The factory to create SSL contexts.
|
1595 | 1622 | * This provides more flexibility to create {@link SSLContext}s
|
|
0 commit comments