You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "gusteycamargo (via GitHub)" <gi...@apache.org> on 2026/10/06 18:29:02 UTC
[PR] [fix][client] Send the pending batch before a non-batched message so deduplication does not drop it [pulsar-client-cpp]
gusteycamargo opened a new pull request, #616:
URL: https://github.com/apache/pulsar-client-cpp/pull/616
Fixes #615
### Motivation
When batching is enabled, a message that cannot be batched (e.g. a delayed message) is sent immediately, while the messages already in the batch container still wait for the batch to be flushed. The non-batched message took the next sequence id, so it reaches the broker before messages with lower sequence ids. With deduplication enabled, the broker then drops the whole batch as a duplicate, while the producer receives `ResultOk` for every message.
The Java client avoids it by flushing the batch container before sending any non-batched message (`ProducerImpl#processOpSendMsg`).
### Modifications
- In `ProducerImpl::sendAsync`, before sending a message that cannot be added to the batch, send the pending batch (`batchMessageAndSend().complete()`), the same way the producer already does when the batch container has no room for the next message.
### Verifying this change
- [ ] Make sure that the change passes the CI checks.
This change added tests and can be verified as follows:
- Added `ClientDeduplicationBatchingTest.testBatchedMessagesBeforeDelayedMessage`, parameterized for `DefaultBatching` and `KeyBasedBatching`: with deduplication enabled on the namespace, it sends 10 batched messages asynchronously and then a delayed one, and reads the topic from the earliest position. Without the fix only 1 of the 11 messages is stored, with it all 11 are.
### Documentation
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `doc-not-needed`
(Bug fix in the producer, no API change)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org