Skip to content

Commit 796c95b

Browse files
authored
[ISSUE #8929] Proxy adds message body empty check when send in grpc protocol (#8930)
1 parent 9202de3 commit 796c95b

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ maven_install(
7171
"org.bouncycastle:bcpkix-jdk15on:1.69",
7272
"com.google.code.gson:gson:2.8.9",
7373
"com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2",
74-
"org.apache.rocketmq:rocketmq-proto:2.0.3",
74+
"org.apache.rocketmq:rocketmq-proto:2.0.4",
7575
"com.google.protobuf:protobuf-java:3.20.1",
7676
"com.google.protobuf:protobuf-java-util:3.20.1",
7777
"com.conversantmedia:disruptor:1.2.10",

pom.xml

+9-11
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<annotations-api.version>6.0.53</annotations-api.version>
127127
<extra-enforcer-rules.version>1.0-beta-4</extra-enforcer-rules.version>
128128
<concurrentlinkedhashmap-lru.version>1.4.2</concurrentlinkedhashmap-lru.version>
129-
<rocketmq-proto.version>2.0.3</rocketmq-proto.version>
129+
<rocketmq-proto.version>2.0.4</rocketmq-proto.version>
130130
<grpc.version>1.53.0</grpc.version>
131131
<protobuf.version>3.20.1</protobuf.version>
132132
<disruptor.version>1.2.10</disruptor.version>
@@ -641,16 +641,8 @@
641641
<version>${rocketmq-proto.version}</version>
642642
<exclusions>
643643
<exclusion>
644-
<groupId>io.grpc</groupId>
645-
<artifactId>grpc-protobuf</artifactId>
646-
</exclusion>
647-
<exclusion>
648-
<groupId>io.grpc</groupId>
649-
<artifactId>grpc-stub</artifactId>
650-
</exclusion>
651-
<exclusion>
652-
<groupId>io.grpc</groupId>
653-
<artifactId>grpc-netty-shaded</artifactId>
644+
<groupId>*</groupId>
645+
<artifactId>*</artifactId>
654646
</exclusion>
655647
</exclusions>
656648
</dependency>
@@ -1097,6 +1089,12 @@
10971089
</exclusion>
10981090
</exclusions>
10991091
</dependency>
1092+
1093+
<dependency>
1094+
<groupId>jakarta.annotation</groupId>
1095+
<artifactId>jakarta.annotation-api</artifactId>
1096+
<version>1.3.5</version>
1097+
</dependency>
11001098
</dependencies>
11011099
</dependencyManagement>
11021100

proxy/src/main/java/org/apache/rocketmq/proxy/config/ProxyConfig.java

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public class ProxyConfig implements ConfigFile {
103103
* max message body size, 0 or negative number means no limit for proxy
104104
*/
105105
private int maxMessageSize = 4 * 1024 * 1024;
106+
/**
107+
* if true, proxy will check message body size and reject msg if it's body is empty
108+
*/
109+
private boolean enableMessageBodyEmptyCheck = true;
106110
/**
107111
* max user property size, 0 or negative number means no limit for proxy
108112
*/
@@ -1525,4 +1529,12 @@ public boolean isEnableBatchAck() {
15251529
public void setEnableBatchAck(boolean enableBatchAck) {
15261530
this.enableBatchAck = enableBatchAck;
15271531
}
1532+
1533+
public boolean isEnableMessageBodyEmptyCheck() {
1534+
return enableMessageBodyEmptyCheck;
1535+
}
1536+
1537+
public void setEnableMessageBodyEmptyCheck(boolean enableMessageBodyEmptyCheck) {
1538+
this.enableMessageBodyEmptyCheck = enableMessageBodyEmptyCheck;
1539+
}
15281540
}

proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ protected int buildSysFlag(apache.rocketmq.v2.Message protoMessage) {
132132
}
133133

134134
protected void validateMessageBodySize(ByteString body) {
135+
if (ConfigurationManager.getProxyConfig().isEnableMessageBodyEmptyCheck()) {
136+
if (body.isEmpty()) {
137+
throw new GrpcProxyException(Code.MESSAGE_BODY_EMPTY, "message body cannot be empty");
138+
}
139+
}
135140
int max = ConfigurationManager.getProxyConfig().getMaxMessageSize();
136141
if (max <= 0) {
137142
return;

0 commit comments

Comments
 (0)