[ISSUE #9195] Propagate MessageBatch user properties to inner messages#10588
[ISSUE #9195] Propagate MessageBatch user properties to inner messages#10588Aias00 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| MessageBatch messageBatch = MessageBatch.generateFromList(messages); | ||
| messageBatch.putUserProperty("name", "value"); | ||
|
|
| @Override | ||
| public void putUserProperty(String name, String value) { | ||
| super.putUserProperty(name, value); | ||
| for (Message message : messages) { | ||
| message.putUserProperty(name, value); | ||
| } | ||
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
967de48 to
e0c0fff
Compare
|
Updated after review: removed the batch-level |
Which Issue(s) This PR Fixes
Fixes #9195
Brief Description
MessageBatchencodes the inner message list viaMessageDecoder.encodeMessages(messages). If a caller sets a user property on theMessageBatchwrapper 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 testResult:
BUILD SUCCESS,Tests run: 17, Failures: 0, Errors: 0, Skipped: 0