Skip to content

[Fix] DLQ Messages will lose system properties when sent from reconsumeLater() - #1392

Merged
RobertIndie merged 1 commit into
apache:masterfrom
geniusjoe:bugfix/dlq-RealTopic-property
Aug 7, 2025
Merged

RobertIndie merged 1 commit into
apache:masterfrom
geniusjoe:bugfix/dlq-RealTopic-property

Conversation

@geniusjoe

Copy link
Copy Markdown
Contributor

Fixes #1388
Master Issue: #907, apache/pulsar#23182

Motivation

Since pulsar sdk does not support AckTimeout() method, we can only use Nack() or ReconsumeLater() to trigger dlq policy and send messages to dlq. We can find system properties(e.g. REAL_TOPIC and ORIGIN_MESSAGE_ID) in these dlq messages.

Refer to issue #1388, before pr #907 dlq_router#run() will directly copy properties to create a new dlq message when receiving a message from dlq.Chan(). But we only define message properties in ReconsumeLater's ReconsumeLaterWithCustomProperties() and not in Nack's dispatcher() before send to this dlq.Chan(), which lead to only dlq messages created by ReconsumeLater() can have these properties.

The above pr replaced this behavior with just adding system properties as soon as creating dlq messages in dlq_router#run(), which use message.topic as REAL_TOPIC property value. But messages sent from ReconsumeLater() ReconsumeLaterWithCustomProperties() do not contain related message.topic fields, in case it will override defined REAL_TOPIC to empty string.

Modifications

  • Add REAL_TOPIC, ORIGIN_MESSAGE_IDY_TIME, ORIGIN_MESSAGE_ID system properties both in ReconsumeLater's ReconsumeLaterWithCustomProperties() and Nack's dispatcher() functions.
  • Add Key, OrderingKey, EventTime message fields both in ReconsumeLater() ReconsumeLaterWithCustomProperties() and dlq_router run() functions to keep consistent with Java realization, so that dlq messages can preserve source message info.
  • Remove adding system properties strategy in dlq_router#run().

Verifying this change

  • Make sure that the change passes the CI checks.

This change updated tests and can be verified as follows:
DLQWithProducerOptions
TestRLQ

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@geniusjoe
geniusjoe force-pushed the bugfix/dlq-RealTopic-property branch from 184037c to 8a81866 Compare July 15, 2025 08:10
@crossoverJie
crossoverJie requested a review from Copilot July 17, 2025 05:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where DLQ (Dead Letter Queue) messages lose system properties when sent from reconsumeLater() method. The fix ensures that system properties like REAL_TOPIC and ORIGIN_MESSAGE_ID are consistently preserved for both Nack() and ReconsumeLater() code paths, while also preserving additional message metadata.

Key changes:

  • Moved system property addition from DLQ router to the source methods (dispatcher() and ReconsumeLaterWithCustomProperties())
  • Added preservation of message metadata (Key, OrderingKey, EventTime) in both DLQ and RLQ flows
  • Updated tests to verify the preservation of all message properties and metadata

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pulsar/message.go Fixed typo in comment ("be be" → "be")
pulsar/dlq_router.go Removed system property addition logic and simplified message creation
pulsar/consumer_partition.go Added system property creation and message metadata preservation for Nack flow
pulsar/consumer_impl.go Enhanced ReconsumeLater to preserve all message metadata and system properties
pulsar/consumer_test.go Added comprehensive tests for message property and metadata preservation

Comment thread pulsar/consumer_partition.go Resolved
Comment thread pulsar/consumer_partition.go Resolved

@RobertIndie RobertIndie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also take a look at the copilot comments?

Comment thread pulsar/consumer_test.go Resolved
@geniusjoe
geniusjoe force-pushed the bugfix/dlq-RealTopic-property branch from 8a81866 to 6c6775e Compare August 6, 2025 14:31
@geniusjoe
geniusjoe force-pushed the bugfix/dlq-RealTopic-property branch from 6c6775e to 9729b65 Compare August 6, 2025 14:50
@RobertIndie RobertIndie added this to the v0.17.0 milestone Aug 7, 2025
@RobertIndie
RobertIndie merged commit b12eccc into apache:master Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing REAL_TOPIC in DLQ message when max deliveries exceeeds

3 participants