BewareMyPower commented on issue #23436:
URL: https://github.com/apache/pulsar/issues/23436#issuecomment-2459525785

   > it doesn't seem to remove messages from pending acks map when batch index 
acks are enabled
   
   The negative acknowledgment is just to trigger the 
`redeliverUnacknowledgedMessages` call for the given messages. For example, the 
following test will pass if you add it to `BatchMessageIndexAckTest`.
   
   ```java
       @Test
       public void test() throws Exception {
           final var topic = "test";
           @Cleanup final var producer = 
pulsarClient.newProducer(Schema.STRING).topic(topic).create();
           var consumer = 
pulsarClient.newConsumer(Schema.STRING).topic(topic).subscriptionName("sub")
                   .subscriptionType(SubscriptionType.Shared)
                   .isAckReceiptEnabled(true)
                   .negativeAckRedeliveryDelay(3, TimeUnit.SECONDS)
                   .enableBatchIndexAcknowledgment(true).subscribe();
           for (int i = 0; i < 3; i++) {
               producer.newMessage().value("msg-" + i).sendAsync();
           }
           producer.flush();
           final var ids = new ArrayList<MessageId>();
           for (int i = 0; i < 3; i++) {
               ids.add(consumer.receive().getMessageId());
           }
           consumer.acknowledge(ids.get(0));
           consumer.acknowledge(ids.get(2));
           consumer.negativeAcknowledge(ids.get(1));
   
           final var msg = consumer.receive();
           Assert.assertEquals(((MessageIdAdv) 
msg.getMessageId()).getBatchIndex(), 1);
       }
   ```
   
   If you have already acknowledged `ids.get(1)`, then call 
`negativeAcknowledge(ids.get(1))` will take no effect. The API docs explain the 
use case: 
https://github.com/apache/pulsar/blob/8eeb0e2e89f8938348d29044d9e1d843a6251067/pulsar-client-api/src/main/java/org/apache/pulsar/client/api/Consumer.java#L199-L206
   
   It assumes that the message has not been acknowledged. Maybe we can improve 
the API docs.


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