feature: [158] Implement global mqtt message storage service, part 2#166
Merged
JavaSaBr merged 28 commits intoMay 9, 2026
Merged
Conversation
…ent-global-mqtt-message-storage-service
…ent-global-mqtt-message-storage-service
…ent-global-mqtt-message-storage-service
…d received publishes
…ce' into feature/158-implement-global-mqtt-message-storage-service-part-2 # Conflicts: # core-service/src/main/java/javasabr/mqtt/service/publish/processor/AbstractIncomingPublishProcessor.java
…ent-global-mqtt-message-storage-service-part-2 # Conflicts: # .github/copilot-instructions.md # application/src/main/java/javasabr/mqtt/broker/application/config/MqttBrokerSpringConfig.java # core-service/src/main/java/javasabr/mqtt/service/message/handler/impl/PublishMqttInMessageHandler.java # core-service/src/main/java/javasabr/mqtt/service/message/handler/impl/SubscribeMqttInMessageHandler.java # core-service/src/main/java/javasabr/mqtt/service/publish/IncomingPublishRouter.java # core-service/src/main/java/javasabr/mqtt/service/publish/PublishDataStorage.java # core-service/src/main/java/javasabr/mqtt/service/publish/PublishDispatcher.java # core-service/src/main/java/javasabr/mqtt/service/publish/RetainPublishService.java # core-service/src/main/java/javasabr/mqtt/service/publish/impl/DefaultIncomingPublishRouter.java # core-service/src/main/java/javasabr/mqtt/service/publish/impl/DefaultPublishDispatcher.java # core-service/src/main/java/javasabr/mqtt/service/publish/impl/InMemoryPublishDataStorage.java # core-service/src/main/java/javasabr/mqtt/service/publish/impl/InMemoryRetainPublishService.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/AbstractIncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/IncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/Qos0IncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/Qos1IncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/Qos2IncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/processor/TrackableIncomingPublishProcessor.java # core-service/src/main/java/javasabr/mqtt/service/publish/sender/AbstractSubscriberPublishSender.java # core-service/src/main/java/javasabr/mqtt/service/publish/sender/Qos0SubscriberPublishSender.java # core-service/src/main/java/javasabr/mqtt/service/publish/sender/SubscriberPublishSender.java # core-service/src/main/java/javasabr/mqtt/service/publish/sender/TrackableSubscriberPublishSender.java # core-service/src/main/java/javasabr/mqtt/service/session/impl/InMemoryNetworkMqttSession.java # core-service/src/test/groovy/javasabr/mqtt/service/IntegrationServiceSpecification.groovy # core-service/src/test/groovy/javasabr/mqtt/service/message/handler/impl/PublishMqttInMessageHandlerTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/message/handler/impl/SubscribeMqttInMessageHandlerTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/publish/processor/Qos0IncomingPublishProcessorTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/publish/processor/Qos1IncomingPublishProcessorTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/publish/processor/Qos2IncomingPublishProcessorTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/publish/processor/QosIncomingPublishProcessorTest.groovy # core-service/src/test/groovy/javasabr/mqtt/service/publish/sender/Qos1SubscriberPublishSenderTest.groovy # model/src/main/java/javasabr/mqtt/model/publish/IncomingPublish.java # model/src/main/java/javasabr/mqtt/model/publish/OutgoingPublish.java # model/src/main/java/javasabr/mqtt/model/publish/Publish.java # model/src/main/java/javasabr/mqtt/model/session/MqttSession.java # model/src/main/java/javasabr/mqtt/model/topic/tree/ConcurrentRetainedMessageTree.java # model/src/main/java/javasabr/mqtt/model/topic/tree/RetainedPublishNode.java # model/src/testFixtures/groovy/javasabr/mqtt/model/subscription/TestPublishFactory.groovy
…ent-global-mqtt-message-storage-service-part-2
crazyrokr
requested changes
May 9, 2026
| if (!retained()) { | ||
| return this; | ||
| } else { | ||
| return new TrackableSimpleOutgoingPublish(incomingPublish, messageId, duplicated, false, qos, subscriptionIds); |
Collaborator
There was a problem hiding this comment.
Could we consider extracting of common part from all children into Publish interface. Something like this:
interface Publish {
public Publish withoutRetained() {
if (!retained()) {
return this;
} else {
return createPublishWithoutRetained();
}
}
and
record TrackableSimpleOutgoingPublish() {
public Publish createPublishWithoutRetained(){
return new TrackableSimpleOutgoingPublish(incomingPublish, messageId, duplicated, false, qos, subscriptionIds)
}
}
Owner
Author
There was a problem hiding this comment.
I don't see any profit from this + we talk about records without inheritance, so your way doesn't solve anything
| Array<StringPair> userProperties) { | ||
| long stamp = storedPublishes.writeLock(); | ||
| try { | ||
| if (storedPublishes.containsKey(publishId)) { |
Collaborator
There was a problem hiding this comment.
Does it worth to do in a separate read lock ?
Owner
Author
There was a problem hiding this comment.
@crazyrokr we don't expect any collisions, so using a read lock here is overhead
| public void removeIfExist(IncomingPublish publish) { | ||
| long stamp = storedPublishes.writeLock(); | ||
| try { | ||
| if (storedPublishes.containsKey(publish.id())) { |
| return publishData; | ||
| long stamp = idToPublishData.writeLock(); | ||
| try { | ||
| if (idToPublishData.containsKey(dataId)) { |
| MqttSession session, | ||
| TrackableMqttMessage message) { | ||
| TrackableMqttMessage message, | ||
| Publish publish) { |
Collaborator
There was a problem hiding this comment.
Should it be IncomingPublish?
Owner
Author
There was a problem hiding this comment.
@crazyrokr currently the lambda doesn't support this type
crazyrokr
approved these changes
May 9, 2026
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.
Issue
#15
Description
This branch extends the publish pipeline around global MQTT message storage and refactors the broker to distinguish more clearly between incoming publishes, outgoing publishes, and the storage/lifecycle around them.
Main changes
1. Introduced dedicated incoming publish storage
IncomingPublishStorageandInMemoryIncomingPublishStorage.store(...)remove(...)removeIfExist(...)increaseConsumerCount(...)decreaseConsumerCount(...)2. Split publish models into incoming and outgoing variants
SimpleIncomingPublishSimpleOutgoingPublishTrackableSimpleOutgoingPublishIncomingPublishandOutgoingPublishare distinct concepts built on the sharedPublishcontract.3. Reworked publish handling flow
PublishMqttInMessageHandlernow:PublishDatafirstIncomingPublishPublishDataif incoming publish registration failssession.generatePublishId()to assign a unique publish identity for storage and tracking.4. Updated incoming publish processors
AbstractIncomingPublishProcessornow works withIncomingPublishdirectly and dispatches through storage-aware lifecycle rules.IncomingPublishStorage.5. Extended session state for stored publish tracking
MqttSessionnow exposesgeneratePublishId().InMemoryNetworkMqttSessionnow maintains a publish-id generator in addition to message-id and data-id generators.6. Updated publisher-to-subscriber delivery model
Documentation and repo conventions
.github/copilot-instructions.mdwas expanded with testing and stateful-service conventions observed in this branch:Overall impact
This branch lays the groundwork for a broker-wide message-storage model by: