Repository navigation
[fix][client] Fix cannot retry chunk messages and send to DLQ - #21048
Merged
Merged
Conversation
RobertIndie
requested review from
BewareMyPower,
liangyepianzhou,
mattisonchao and
poorbarcode
August 23, 2023 04:41
poorbarcode
reviewed
Aug 30, 2023
poorbarcode
reviewed
Aug 30, 2023
Member
Author
|
Hi, @poorbarcode , I have added the timeout of receive opeartion for the test. PTAL again. Thanks. |
poorbarcode
reviewed
Aug 30, 2023
codelipenghui
approved these changes
Aug 30, 2023
poorbarcode
approved these changes
Aug 30, 2023
liangyepianzhou
approved these changes
Aug 30, 2023
RobertIndie
added a commit
that referenced
this pull request
Aug 31, 2023
(cherry picked from commit 99e3fea)
RobertIndie
added a commit
that referenced
this pull request
Aug 31, 2023
(cherry picked from commit 99e3fea)
RobertIndie
added a commit
that referenced
this pull request
Sep 5, 2023
(cherry picked from commit 99e3fea)
Closed
1 of 2 tasks
RobertIndie
pushed a commit
to apache/pulsar-client-go
that referenced
this pull request
Jun 29, 2026
…tion tests (#1511) Master Issue: apache/pulsar#21048 Related Issue: #805 ### Motivation In the Java SDK (PR apache/pulsar#21048), the DLQ/RLQ producers are hardcoded with `enableBatching(false).enableChunking(true)` to ensure large chunked messages can be forwarded to DLQ/RLQ topics successfully. However, in the Go SDK, the DLQ/RLQ producers are created using `DLQPolicy.ProducerOptions`, which defaults to a zero-value `ProducerOptions{}` (i.e., `EnableChunking: false`, `DisableBatching: false`). This means that if a producer sends a chunked message larger than the broker's `maxMessageSize`, and the consumer is configured with DLQ/RLQ, the DLQ/RLQ producer will fail to forward the message because it cannot chunk it. We considered automatically enabling chunking in the DLQ/RLQ producers when the user has not explicitly configured `ProducerOptions`. However, since `EnableChunking` and `DisableBatching` are both `bool` fields with a zero value of `false`, there is no way to distinguish between: - The user intentionally setting them to `false` (meaning "I don't want chunking") - The user not configuring them at all (meaning "I didn't think about it") Automatically overriding these values would break backward compatibility for users who explicitly set `EnableChunking: false`. Therefore, instead of changing the default behavior, we add documentation to guide users to enable chunking in `DLQPolicy.ProducerOptions` when using chunked messages with DLQ/RLQ. ### Modifications - Added a note to the `EnableChunking` field documentation in `ProducerOptions` (`producer.go`) explaining that when chunking is enabled and the consumer uses DLQ/RLQ, it is recommended to also enable chunking in `DLQPolicy.ProducerOptions`. - Added a note to the `DLQPolicy.ProducerOptions` field documentation (`consumer.go`) explaining that if the messages being consumed were produced with chunking enabled, it is recommended to also enable chunking here. This helps in decoupled producer/consumer scenarios where the consumer developer may not be aware of the producer's chunking configuration. - Added `TestChunkReconsumeLater` integration test to verify chunked messages (5MB, exceeding broker maxMessageSize) can be sent to the retry topic via `ReconsumeLater` and routed to DLQ after exceeding max retries, when `DLQPolicy.ProducerOptions` has chunking enabled. - Added `TestChunkDLQWithNack` integration test to verify chunked messages (5MB) are routed to DLQ after exceeding max redelivery count via `Nack`, when `DLQPolicy.ProducerOptions` has chunking enabled. ### Verifying this change This change added tests and can be verified as follows: - Added `TestChunkReconsumeLater`: sends a 5MB chunked message, verifies it flows through retry topic via `ReconsumeLater` and eventually lands in DLQ after exceeding `MaxDeliveries`. - Added `TestChunkDLQWithNack`: sends a 5MB chunked message, verifies it is routed to DLQ after exceeding max redelivery count via `Nack`, with original properties preserved. Both tests use payloads larger than broker `maxMessageSize` (~1MB) to ensure that DLQ/RLQ producers **must** have chunking enabled to successfully forward messages. Without chunking enabled in `DLQPolicy.ProducerOptions`, these tests would timeout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20934
Motivation
If the consumer receives a chunked message, it currently couldn't retry it or send it to the DLQ. It will throw an exception like this:
This is because we don't enable the chunking for the retry producer and the DLQ producer in the consumer.
This PR enables the chunking feature for retry and DLQ producers. However, we cannot enable both chunking and batching simultaneously. Therefore, the trade-off of this change is that we have to turn off the batching for the DLQ producer, while the retry producer has already done so. This is acceptable because the DLQ producer usually has low traffic. It does not have a significant impact on the performance.
This PR also addresses the following two issues:
Issue A: Consumers cannot redeliver chunked messages
When the consumer attempts to redeliver a chunked message, the message ID is reconstructed in
discardBatch, which causes this message ID to lose the chunk information. The comparison in theunAckedChunkedMessageIdSequenceMapwill fail. The consumer will never be able to redeliver chunked messages.We should not reconstruct the chunked message ID in
discardBatch. The chunk message ID does not contain any batch information.Issue B: The chunked message cannot be resent
When the producer resends the chunked message, the chunk id in the message metadata of all subsequent chunks will be set to the last chunk id.
The root cause is that the producer shares the same MessageMetadata for all chunks in a chunked message.
pulsar/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
Lines 696 to 700 in 4634311
Therefore, when
op.rePopulateis called, the chunk id infinalMsgMetadatais pointed to the last chunk. Suppose we have a large message with 3 chunks. The producer may end up sending all 3 messages with the same chunk id3. The consumer will treat these messages as corrupted and ignore them, preventing it from receiving any of these messages.Modification
testDeadLetterTopic.Verifying this change
This change added tests.
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
docdoc-requireddoc-not-neededdoc-completeMatching PR in forked repository
PR in forked repository: