Implement MQTT Topic Subscription in MqttManager (CATROID-1674) - #5233
Open
Paras-ydv wants to merge 2 commits into
Open
Implement MQTT Topic Subscription in MqttManager (CATROID-1674)#5233Paras-ydv wants to merge 2 commits into
Paras-ydv wants to merge 2 commits into
Conversation
harshsomankar123-tech
marked this pull request as draft
August 8, 2026 15:11
Paras-ydv
marked this pull request as ready for review
August 9, 2026 11:40
Paras-ydv
marked this pull request as draft
August 9, 2026 11:40
14 tasks
- Add publish() to MqttClientInterface and PahoMqttClient - Implement publish() in MqttManager with topic validation (blank, wildcards), QoS range check (0-2), and retained flag support - Lazy-connect before publishing if no active connection exists - Rename publishFromContext() to avoid Detekt MethodOverloading - Log failures without crashing; no forced unwrap - Add comprehensive unit tests: empty payload, QoS boundaries, retained flag, lazy connect, no reconnect when already connected, no publish when connect fails (51 tests total)
Paras-ydv
force-pushed
the
CATROID-1674
branch
from
September 2, 2026 15:49
82083c5 to
841d3b7
Compare
|
Paras-ydv
marked this pull request as ready for review
September 2, 2026 16:07
harshsomankar123-tech
requested review from
harshsomankar123-tech,
reichli and
wslany
September 8, 2026 10:06
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.



Summary
Extends
MqttManagerto support subscribing to and unsubscribing from MQTT topics.Dependency notice: this PR builds on CATROID-1673 (#5225), which is not merged yet, so that commit is included here to keep the branch buildable on its own. Please merge #5225 first; this branch will then be rebased and the commit will drop out by itself.
The branch previously also carried the dependency, settings and connection lifecycle commits. Those have since been merged (#5220, #5222), so the branch has been rebased onto
developand they are gone. Two commits remain.This ticket is scoped to subscription management only. Handling the messages that arrive on a subscribed topic is a separate ticket.
CATROID-1674 — Subscribe implementation
Changes
subscribe(topic, qos)andunsubscribe(topic)toMqttClientInterfaceand implemented both inPahoMqttClientMqttManager.subscribe()validates the topic is not blank and the QoS is in range 0–2. Unlike publish, the#and+wildcards are accepted here, since they are only legal in subscriptionsMap<String, Int>of topic to QoS, exposed read-only asactiveSubscriptions, and cleared ondisconnect()truewithout calling the client againsubscribeFromContext()convenience wrapper for the brick layerunsubscribe()is idempotent and returnstruewhen the topic was never subscribedfalserather than thrownTests
29 new tests:
#and+)truewithout re-calling the client, including with a different QoSfalsewithout crashingtruewithout calling the clientfalsewithout crashingdisconnect(), and subscribing works again afterwardsFull suite: 4709 tests, 0 failures.
A note on the rebase
Two existing tests were updated.
MqttManagernow takes anMqttClientFactoryinstead of a client instance, following the change made during the CATROID-1671 review, so tests that assumed an injected client have to connect first. Without that,testSubscribeAfterDisconnectSucceedsAgaindid not compile.The conflict in
disconnect()was resolved in favour of the version ondevelop, which guards onmqttClient == nullinside asynchronizedblock rather than on!isConnected, withsubscriptions.clear()added into itsfinally. The null guard is the safer of the two, since it still cleans up when the connection has dropped but the client object is alive.Acceptance criteria
subscribe()andunsubscribe()API added toMqttManagerMqttClientInterfaceandPahoMqttClientYour Checklist