Skip to content

[ISSUE #9195] Propagate MessageBatch user properties to inner messages#10588

Open
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/message-batch-user-property
Open

[ISSUE #9195] Propagate MessageBatch user properties to inner messages#10588
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/message-batch-user-property

Conversation

@Aias00

@Aias00 Aias00 commented Jul 3, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #9195

Brief Description

MessageBatch encodes the inner message list via MessageDecoder.encodeMessages(messages). If a caller sets a user property on the MessageBatch wrapper itself, that wrapper property is not part of the encoded inner messages and therefore is not visible after decoding or consumption.

This PR makes MessageBatch.putUserProperty(...) propagate the user property to every inner message while still preserving the property on the wrapper. This keeps batch-level user property setters aligned with the payload that is actually encoded and consumed.

The tests also cover the existing behavior where user properties already set on inner messages are preserved during batch encode/decode.

How Did You Test This Change?

  • mvn -pl common -Dtest=MessageEncodeDecodeTest,MessageBatchTest,MessageTest test

Result: BUILD SUCCESS, Tests run: 17, Failures: 0, Errors: 0, Skipped: 0

Copilot AI review requested due to automatic review settings July 3, 2026 07:31

Copilot AI left a comment

Copy link
Copy Markdown

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 addresses issue #9195 by ensuring that user properties set on a MessageBatch wrapper are propagated to all inner Message instances, so those properties are actually present in the encoded/decoded payload consumed by clients.

Changes:

  • Override MessageBatch.putUserProperty(...) to copy the property onto each inner message.
  • Add encode/decode tests to validate user-property behavior for MessageBatch.

Reviewed changes

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

File Description
common/src/main/java/org/apache/rocketmq/common/message/MessageBatch.java Propagates batch-level user properties onto inner messages during putUserProperty(...).
common/src/test/java/org/apache/rocketmq/common/MessageEncodeDecodeTest.java Adds tests asserting inner-message user properties are present after batch encode/decode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +86 to +88
MessageBatch messageBatch = MessageBatch.generateFromList(messages);
messageBatch.putUserProperty("name", "value");

Comment on lines +42 to +48
@Override
public void putUserProperty(String name, String value) {
super.putUserProperty(name, value);
for (Message message : messages) {
message.putUserProperty(name, value);
}
}
@codecov-commenter

codecov-commenter commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.18%. Comparing base (8242c1e) to head (e0c0fff).

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10588      +/-   ##
=============================================
- Coverage      48.26%   48.18%   -0.09%     
+ Complexity     13433    13415      -18     
=============================================
  Files           1378     1378              
  Lines         100817   100824       +7     
  Branches       13040    13042       +2     
=============================================
- Hits           48660    48577      -83     
- Misses         46211    46288      +77     
- Partials        5946     5959      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

MessageBatch encodes the inner message list, so user properties set only on the MessageBatch wrapper are not visible after decoding. Propagating batch-level user properties to each inner message makes MessageBatch.putUserProperty behave consistently with the encoded message payload consumed downstream.

Constraint: Related to apache#9195
Rejected: Copy wrapper properties only during generateFromList | callers can set MessageBatch properties after construction
Confidence: medium
Scope-risk: narrow
Directive: Keep MessageBatch wrapper properties and inner message properties aligned for user-facing setters that affect encoded payload semantics.
Tested: mvn -pl common -Dtest=MessageEncodeDecodeTest,MessageBatchTest,MessageTest test
Not-tested: Full repository test suite
@Aias00 Aias00 force-pushed the fix/message-batch-user-property branch from 967de48 to e0c0fff Compare July 5, 2026 08:03
@Aias00

Aias00 commented Jul 5, 2026

Copy link
Copy Markdown
Author

Updated after review: removed the batch-level putUserProperty call from the inner-message preservation test, and added a null guard in MessageBatch.putUserProperty so a publicly constructed MessageBatch(null) still records the wrapper property without throwing while propagation is skipped. Also added a focused null-messages regression test. Verified with mvn -pl common -Dtest=MessageEncodeDecodeTest,MessageBatchTest,MessageTest test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MessageBatch Custom Attribute Value Lost

3 participants