This is an automated email from the ASF dual-hosted git repository. lizhimin pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push: new 796c95b928 [ISSUE #8929] Proxy adds message body empty check when send in grpc protocol (#8930) 796c95b928 is described below commit 796c95b9283af301438cdba8582c2ff6f286a679 Author: qianye <wuxingcan....@alibaba-inc.com> AuthorDate: Thu Nov 21 16:40:48 2024 +0800 [ISSUE #8929] Proxy adds message body empty check when send in grpc protocol (#8930) --- WORKSPACE | 2 +- pom.xml | 20 +++++++++----------- .../apache/rocketmq/proxy/config/ProxyConfig.java | 12 ++++++++++++ .../proxy/grpc/v2/producer/SendMessageActivity.java | 5 +++++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 9b06bc6341..9125a67f88 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -71,7 +71,7 @@ maven_install( "org.bouncycastle:bcpkix-jdk15on:1.69", "com.google.code.gson:gson:2.8.9", "com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2", - "org.apache.rocketmq:rocketmq-proto:2.0.3", + "org.apache.rocketmq:rocketmq-proto:2.0.4", "com.google.protobuf:protobuf-java:3.20.1", "com.google.protobuf:protobuf-java-util:3.20.1", "com.conversantmedia:disruptor:1.2.10", diff --git a/pom.xml b/pom.xml index 33db3c7f48..ddc8fc81b6 100644 --- a/pom.xml +++ b/pom.xml @@ -126,7 +126,7 @@ <annotations-api.version>6.0.53</annotations-api.version> <extra-enforcer-rules.version>1.0-beta-4</extra-enforcer-rules.version> <concurrentlinkedhashmap-lru.version>1.4.2</concurrentlinkedhashmap-lru.version> - <rocketmq-proto.version>2.0.3</rocketmq-proto.version> + <rocketmq-proto.version>2.0.4</rocketmq-proto.version> <grpc.version>1.53.0</grpc.version> <protobuf.version>3.20.1</protobuf.version> <disruptor.version>1.2.10</disruptor.version> @@ -641,16 +641,8 @@ <version>${rocketmq-proto.version}</version> <exclusions> <exclusion> - <groupId>io.grpc</groupId> - <artifactId>grpc-protobuf</artifactId> - </exclusion> - <exclusion> - <groupId>io.grpc</groupId> - <artifactId>grpc-stub</artifactId> - </exclusion> - <exclusion> - <groupId>io.grpc</groupId> - <artifactId>grpc-netty-shaded</artifactId> + <groupId>*</groupId> + <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> @@ -1097,6 +1089,12 @@ </exclusion> </exclusions> </dependency> + + <dependency> + <groupId>jakarta.annotation</groupId> + <artifactId>jakarta.annotation-api</artifactId> + <version>1.3.5</version> + </dependency> </dependencies> </dependencyManagement> diff --git a/proxy/src/main/java/org/apache/rocketmq/proxy/config/ProxyConfig.java b/proxy/src/main/java/org/apache/rocketmq/proxy/config/ProxyConfig.java index 9901c8ea1f..3b09b1388f 100644 --- a/proxy/src/main/java/org/apache/rocketmq/proxy/config/ProxyConfig.java +++ b/proxy/src/main/java/org/apache/rocketmq/proxy/config/ProxyConfig.java @@ -103,6 +103,10 @@ public class ProxyConfig implements ConfigFile { * max message body size, 0 or negative number means no limit for proxy */ private int maxMessageSize = 4 * 1024 * 1024; + /** + * if true, proxy will check message body size and reject msg if it's body is empty + */ + private boolean enableMessageBodyEmptyCheck = true; /** * max user property size, 0 or negative number means no limit for proxy */ @@ -1525,4 +1529,12 @@ public class ProxyConfig implements ConfigFile { public void setEnableBatchAck(boolean enableBatchAck) { this.enableBatchAck = enableBatchAck; } + + public boolean isEnableMessageBodyEmptyCheck() { + return enableMessageBodyEmptyCheck; + } + + public void setEnableMessageBodyEmptyCheck(boolean enableMessageBodyEmptyCheck) { + this.enableMessageBodyEmptyCheck = enableMessageBodyEmptyCheck; + } } diff --git a/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java b/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java index 8679bfbe38..8a3d315c68 100644 --- a/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java +++ b/proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java @@ -132,6 +132,11 @@ public class SendMessageActivity extends AbstractMessingActivity { } protected void validateMessageBodySize(ByteString body) { + if (ConfigurationManager.getProxyConfig().isEnableMessageBodyEmptyCheck()) { + if (body.isEmpty()) { + throw new GrpcProxyException(Code.MESSAGE_BODY_EMPTY, "message body cannot be empty"); + } + } int max = ConfigurationManager.getProxyConfig().getMaxMessageSize(); if (max <= 0) { return;