Eppiehu opened a new issue, #11415: URL: https://github.com/apache/rocketmq/issues/11415
### Before Creating the Bug Report - [x] I found a bug in this repository rather than a support question. - [x] I searched existing Issues and PRs and did not find the same fix. - [x] I confirmed that this issue belongs to apache/rocketmq. ### Runtime platform environment Windows 11, PowerShell, Maven 3.9.16. ### RocketMQ version 5.5.1, develop. The affected production file was checked against the current official develop branch. ### JDK Version Eclipse Temurin OpenJDK 17.0.19. ### Describe the Bug [`ConsumeMessageCommand.executeDefault`](https://github.com/apache/rocketmq/blob/develop/tools/src/main/java/org/apache/rocketmq/tools/command/message/ConsumeMessageCommand.java#L270) subtracts `maxOffset - minOffset + 1` from the remaining `-c` message limit for each queue. The extra subtraction can exhaust the limit before the command visits another queue containing messages. A queue with `minOffset == maxOffset` also consumes one unit of the limit despite containing no messages. ### Steps to Reproduce Use a mocked `DefaultMQPullConsumer` and a `LinkedHashSet` containing two queues in deterministic order: 1. Set `minOffset=0` and `maxOffset=1` for each queue and return one message from each. 2. Execute `consumeMessage` with the arguments `{"-t", "mytopic", "-c", "2"}`. 3. Count the printed messages. After the first queue, the code calculates `countLeft = 2 - (1 - 0) - 1 = 0`. The command then skips the second queue. The regression test fails with 2 expected messages versus 1 actual message. Another boundary case is an empty first queue followed by a one-message queue with `-c 1`: the empty queue exhausts the limit and the non-empty queue is skipped. ### What Did You Expect to See? With two one-message queues and `-c 2`, both messages should be printed. A queue whose minimum and maximum offsets are equal should not consume the remaining message limit. ### What Did You See Instead? Only the first message is printed in the two-queue case, even though another message is available. ### Additional Context The available offset range is `maxOffset - minOffset`; the extra `-1` in the remaining-limit calculation is unnecessary. I have prepared a one-line fix and deterministic mocked-consumer tests for empty queues, limits spanning queues, and stopping at the requested limit. The tests do not require a running cluster. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
