chennaji9 opened a new issue, #11282:
URL: https://github.com/apache/rocketmq/issues/11282

   ### Description
   
   The lite-pull assign example 
`example/src/main/java/org/apache/rocketmq/example/simple/LitePullConsumerAssign.java`
 crashes for topics with a single message queue:
   
   ```java
   Collection<MessageQueue> mqSet = 
litePullConsumer.fetchMessageQueues("TopicTest");
   List<MessageQueue> list = new ArrayList<>(mqSet);
   List<MessageQueue> assignList = new ArrayList<>();
   for (int i = 0; i < list.size() / 2; i++) {
       assignList.add(list.get(i));
   }
   litePullConsumer.assign(assignList);
   litePullConsumer.seek(assignList.get(0), 10);
   ```
   
   `list.size() / 2` is integer division. With 1 queue the loop body never 
executes, `assignList` stays empty, and `assignList.get(0)` throws 
`IndexOutOfBoundsException`. A single-queue topic is a perfectly legal setup 
(fresh topics, small test clusters), so the example is unusable there. (With 3 
queues it also assigns only 1 queue — arguably not "half" either.)
   
   ### Expected behavior
   
   The example should assign at least one queue whenever the topic has queues — 
e.g. use ceiling division `(list.size() + 1) / 2` so 1 queue → 1 assigned, 3 → 
2, 4 → 2 — instead of crashing on `assignList.get(0)`.


-- 
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]

Reply via email to