Expose MQTT publish metadata to custom payload formatters - #18628
Open
Hanabi9248 wants to merge 3 commits into
Open
Hanabi9248 wants to merge 3 commits into
Hanabi9248 wants to merge 3 commits into
Conversation
Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The implementation is backward-compatible, documented, and adequately tests payload lifecycle and dispatch behavior.
Pull request overview
Exposes MQTT publication metadata to custom payload formatters while preserving backward compatibility.
Changes:
- Adds a metadata-aware formatter callback.
- Passes full publications through the handler.
- Documents and tests dispatch and payload ownership.
File summaries
| File | Description |
|---|---|
PayloadFormatter.java |
Adds the backward-compatible callback. |
MPPPublishHandler.java |
Dispatches complete publications. |
PayloadFormatterContextTest.java |
Tests delegation, dispatch, and release behavior. |
README.md |
Documents metadata access and payload lifetime. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Description
Fixes #18625.
Pass the complete MQTT publication to custom payload formatters so they can use the client ID, username and QoS alongside the topic and payload.
The new
formatMessage(InterceptPublishMessage)default method delegates toformat(String, ByteBuf), which retains the existing payload-only fallback. Existing formatters need no changes. A separate method name also avoids making existingformat(null)calls ambiguous. The broker still owns and releases the payload; the customization guide documents its lifetime.Tests
On JDK 25, the 30-module Maven reactor build and all 11 MQTT tests passed:
mvn -pl external-service-impl/mqtt -am test \ -Dtest=PayloadFormatterContextTest,JSONPayloadFormatterTest,LinePayloadFormatterTest \ -Dsurefire.failIfNoSpecifiedTests=falseThe new tests cover payload-only and topic-aware formatters, handler dispatch, and payload release when a formatter returns or throws. Both handler tests fail when run against the old handler. Cluster integration tests were not run.