Skip to content

Allow MQTTHandlers to replace other MQTTHandlers - #3656

Open
richturner wants to merge 6 commits into
mainfrom
worktree-mqtt-provisioning-handler-override
Open

richturner wants to merge 6 commits into
mainfrom
worktree-mqtt-provisioning-handler-override

Conversation

@richturner

Copy link
Copy Markdown
Member

This PR introduces MQTTHandler.getReplacedHandlers() to allow one MQTTHandler to replace one or more other MQTTHandler(s) by class name.

This is an alternative approach to #3590 which this PR also reverts.

Restores the original `provisioning` topic token changed in #3590. Custom
projects that need the old mechanism on this topic can instead replace the
built-in handler. The X.509 challenge prefix change from #3590 is kept.
Adds `MQTTHandler.getReplacedHandlers()` so a custom project can take over
the topic of a built-in handler (e.g. `UserAssetProvisioningMQTTHandler`).
A handler that extends another loaded handler replaces it implicitly.
Replaced handlers are discarded on load, so they are never initialized or
started and never consume messages; ordering by priority alone was not
enough because every handler receives published messages on its topics.
stop() reloaded the handlers via ServiceLoader, so it stopped new instances
that were never initialized instead of the running ones, and ignored
replaced handlers. It now stops the loaded handlers in reverse priority order.
@richturner

Copy link
Copy Markdown
Member Author

Validated this in a custom project and it works

@ebariaux ebariaux 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.

Other codex findings

  • [P2] Test which handler instances receive lifecycle callbacks — manager/src/main/java/org/openremote/manager/mqtt/MQTTBrokerService.java:462-463

X509ProvisioningProofTest constructs its handler directly, so it would still pass if the broker initialized a replaced provider or reverted to stopping freshly loaded instances. Add a Spock unit spec in manager/src/test/groovy with a replacement and an unrelated peer; assert that only the selected instances initialize and start, and that those same instances stop once in reverse order.

And you did not revert the change on the challenge, so this still needs to be indicated as a breaking change for this release.

@richturner

Copy link
Copy Markdown
Member Author

Changes made based on the review; prefix revert means the PR no longer needs the Breaking Change label.

@richturner
richturner requested a review from ebariaux December 3, 2026 09:23
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

2 participants