intkuroky commented on PR #1411: URL: https://github.com/apache/pulsar-client-go/pull/1411#issuecomment-3268686801
> How could the out-of-order issue happen? Yes, the sending operation is indeed executed within the same event loop. However, the generation of sequenceID does not occur within this event loop. This PR is precisely to move the sequenceID generation step into the same event loop. It is precisely because the generation of sequenceID and message sending are not both in the same event loop that this leads to potential out-of-order issues. For example: ` producer, err := client.CreateProducer(pulsar.ProducerOptions{ BatchingMaxPublishDelay: time.Second, // Let the batch operation occur after the single message operation }) producer.SendAsync(context.Background(), &pulsar.ProducerMessage{ Payload: []byte("batch messages"), }, func(id pulsar.MessageID, message *pulsar.ProducerMessage, err error) { // id: -1:-1:0 }) time.Sleep(5e8) // Ensure that genSingleMessageMetadataInBatch is executed first with sequenceID set to 1 // 1. genSingleMessageMetadataInBatch -> updateSingleMessageMetadataSeqID -> sequenceID = 1 producer.SendAsync(context.Background(), &pulsar.ProducerMessage{ Payload: []byte("single message"), DeliverAt: time.Now(), }, func(id pulsar.MessageID, message *pulsar.ProducerMessage, err error) { // }) // 2. updateMetaData -> sequenceID = 2 // 3. publishing a single message (payload:"single message" sequenceID:2) // 4. 1s interval ticker fires -> Flushing batch messages (payload:"batch messages" sequenceID:1)` -- 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: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org