This is an automated email from the ASF dual-hosted git repository.
ShannonDing 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 2a6ec6feb2 [ISSUE #11572] fix(tools): bound mqadmin consumeMessage
pull batch size (#11573)
2a6ec6feb2 is described below
commit 2a6ec6feb25de18b81e1047ab17aace92126cee5
Author: frotmo <[email protected]>
AuthorDate: Mon Nov 23 19:04:31 2026 +0800
[ISSUE #11572] fix(tools): bound mqadmin consumeMessage pull batch size
(#11573)
---
.../command/message/ConsumeMessageCommand.java | 7 ++++-
.../command/message/ConsumeMessageCommandTest.java | 36 ++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git
a/tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
b/tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
index d029c34d5c..1c55090ccf 100644
---
a/tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
+++
b/tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java
@@ -33,6 +33,9 @@ import java.util.Set;
public class ConsumeMessageCommand implements SubCommand {
+ // Keep each pull bounded; the pull API takes an int and brokers cap
batches at 32/8.
+ private static final int PULL_BATCH_SIZE = 32;
+
private String topic = null;
private long messageCount = 128;
private DefaultMQPullConsumer defaultMQPullConsumer;
@@ -217,7 +220,9 @@ public class ConsumeMessageCommand implements SubCommand {
for (long offset = minOffset; offset <= maxOffset; ) {
PullResult pullResult = null;
try {
- pullResult = defaultMQPullConsumer.pull(mq, "*", offset,
(int)(maxOffset - offset + 1));
+ long remaining = maxOffset - offset;
+ int maxNums = remaining >= PULL_BATCH_SIZE ? PULL_BATCH_SIZE :
(int) (remaining + 1);
+ pullResult = defaultMQPullConsumer.pull(mq, "*", offset,
maxNums);
} catch (Exception e) {
e.printStackTrace();
return;
diff --git
a/tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
b/tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
index ad8808529b..680e4f8c5f 100644
---
a/tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
+++
b/tools/src/test/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommandTest.java
@@ -26,6 +26,7 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
@@ -142,6 +143,41 @@ public class ConsumeMessageCommandTest {
Assert.assertTrue(s.contains("Consume ok"));
}
+ @Test
+ public void testExecuteDefaultWithLargeQueueUsesBoundedPullBatch() throws
Exception {
+ ConsumeMessageCommand command = new ConsumeMessageCommand();
+ DefaultMQPullConsumer consumer = mock(DefaultMQPullConsumer.class);
+ MessageQueue queue = new MessageQueue("mytopic", "broker-a", 0);
+
+
when(consumer.fetchSubscribeMessageQueues("mytopic")).thenReturn(Collections.singleton(queue));
+ when(consumer.minOffset(queue)).thenReturn(0L);
+ when(consumer.maxOffset(queue)).thenReturn(3_000_000_000L);
+
+ AtomicInteger maxNums = new AtomicInteger();
+ when(consumer.pull(eq(queue), eq("*"), anyLong(),
anyInt())).thenAnswer(invocation -> {
+ maxNums.set(invocation.getArgument(3));
+ return new PullResult(PullStatus.NO_NEW_MSG, 3_000_000_000L, 0L,
3_000_000_000L,
+ Collections.emptyList());
+ });
+
+ Field consumerField =
ConsumeMessageCommand.class.getDeclaredField("defaultMQPullConsumer");
+ consumerField.setAccessible(true);
+ consumerField.set(command, consumer);
+
+ Options options = command.buildCommandlineOptions(new Options());
+ CommandLine commandLine = new DefaultParser().parse(options,
+ new String[] {"-t", "mytopic", "-c", "3000000000"});
+ PrintStream originalOut = System.out;
+ try {
+ System.setOut(new PrintStream(new ByteArrayOutputStream()));
+ command.execute(commandLine, options, null);
+ } finally {
+ System.setOut(originalOut);
+ }
+
+ Assert.assertEquals(32, maxNums.get());
+ }
+
@Test
public void testExecuteDefaultWithEmptyQueueFirst() throws Exception {
assertDefaultConsumption(new int[] {0, 1}, 1, 1);