BewareMyPower commented on PR #1301:
URL: 
https://github.com/apache/pulsar-client-go/pull/1301#issuecomment-2446616656

   ### The 1st question
   
   What's confusing is the tracking message ID itself. The existing `AckID` 
method's semantic is wrong. Let's look at the following example with `AckID`:
   
   ```golang
   func TestMyAck(t *testing.T) {
        client, err := NewClient(ClientOptions{
                URL: lookupURL,
        })
        assert.Nil(t, err)
        defer client.Close()
   
        topic := fmt.Sprintf("test-my-ack-%v", time.Now().Nanosecond())
        createConsumer := func() Consumer {
                consumer, err := client.Subscribe(ConsumerOptions{
                        Topic:                       topic,
                        SubscriptionName:            "my-sub",
                        SubscriptionInitialPosition: 
SubscriptionPositionEarliest,
                        Type:                        Shared,
                        AckWithResponse:             true,
                })
                assert.Nil(t, err)
                return consumer
        }
        consumer := createConsumer()
        sendMessages(t, client, topic, 0, 2, true) // send 0 and 1 in the same 
batch
        msgs := receiveMessages(t, consumer, 2)
        for i := 0; i < 2; i++ {
                fmt.Println("Received message: ", string(msgs[i].Payload()), 
msgs[i].ID())
        }
   
        if err := consumer.AckID(msgs[0].ID()); err != nil {
                fmt.Println("Ack message 0 failed: ", err.Error())
        } else {
                fmt.Println("Ack message 0 success")
        }
        consumer.Close()
   
        consumer = createConsumer()
        msgs = receiveMessages(t, consumer, 1)
        fmt.Println("Received message: ", string(msgs[0].Payload()), 
msgs[0].ID())
   }
   ```
   
   Outputs:
   
   ```
   Received message:  msg-0 9:0:0
   Received message:  msg-1 9:0:0
   Ack message 0 success
   Received message:  msg-0 9:0:0
   ```
   
   From the perspective from user side:
   - "msg-0"'s message ID has been acknowledged successfully
   - "msg-0" was delivered again after restarting the consumer
   
   Actually this API implements `AckWithResponse` with correct semantics. 
Replacing the `AckID` call with:
   
   ```golang
        for msgID, err := range consumer.AckIDList([]MessageID{msgs[0].ID()}) {
                fmt.Println("Failed to acknowledge ", msgID, err.Error())
        }
   ```
   
   The outputs will be:
   
   ```
   Received message:  msg-0 10:0:0
   Received message:  msg-1 10:0:0
   Failed to acknowledge  10:0:0 incomplete batch
   Received message:  msg-0 10:0:0
   ```
   
   P.S. we should fix the `String()` method of message ID.
   
   Users should add the failed message ID to the next message ID list passed to 
`AckIDList`. Acknowledging the same message ID 
   
   IMO, we should make batch index ACK enabled by default for both client side 
and server side. The current default behavior is really confusing.
   
   ### The 2nd question
   
   `ackIDCommon` is an abstraction for acknowledgment on a single message ID. 
When `AckWithResponse` is true, we cannot reuse this method because we should 
avoid sending N requests.


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