Skip to content

Feature/topic rewriting#932

Draft
hylkevds wants to merge 3 commits intomoquette-io:mainfrom
FraunhoferIOSB:feature/topic_rewriting
Draft

Feature/topic rewriting#932
hylkevds wants to merge 3 commits intomoquette-io:mainfrom
FraunhoferIOSB:feature/topic_rewriting

Conversation

@hylkevds
Copy link
Collaborator

This PR is the reason I made #931, since that PR makes this one a lot simpler :)
There is no rush for a detailed code review on this, but it may provide some context for the other one, and we may need to discuss if this is a feature that fits Moquette in the first place.

What does this PR do?

Topic rewriting, meaning the server internally changes the topic that the client subscribes to, without the client noticing. The rewriting is done by a class implementing the TopicRewriter interface that can be set when starting the Broker.

The three main use cases are:

  • Migrating to a new topic structure: When one wants to change the topic structure, but it's not feasible to update all clients in one go. The publishers can change to the new structure, and old clients have their subscriptions rewritten for the new structure, without them noticing. Of course this assumes the messages themselves don't change.
  • Topic normalisation: When the same message is sent to different topics, these can be merged into one topic for the server, reducing load. For instance, in the OGC SensorThings API, a client can choose which details to receive when something changes on the server by adding $select. Client subscribing to v1.1/Things?$select=id,name would receive the same messages as those subscribing to v1.1/Things?$select=name,id, but the embedding server needs to publish two messages, one for each topic. With topic rewriting, these topics can be merged into one topic, meaning the embedding server only needs to publish one message.
  • Topic de-normalisation: If the topic structure is fixed, but want to add fine-grained access-control, meaning which exact messages a client receives depends on the user(group). Topic rewriting allows the subscriptions to be separated based on the user(group), and the embedding server can publish messages on those de-normalised topics based on this user(group) information.

I'm currently testing it with a branch of FROST-Server to see if it works as expected.

It currently only rewrites topic on subscriptions, not on publishes. If there is interest, I could implement that as well, though I currently don't need that.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the Changelog if it's a feature or a fix that has to be reported

Related issues

hylkevds and others added 3 commits March 9, 2026 16:26
Subscription information was being converted back and forth between several classes,
resulting in much unneeded object creation. But in the end it would always end up as Subscription.
- This removes all the intermediate Objects, simplifying the code.
- This includes the removal of the SharedSubscription class, since in the end, those are also turned into normal
  Subscriptions, making the extra class meaningless.
- The logic contained many superfluous if/else checks for subscriptionIdentifiers caused by the wrapping
  and unwrapping of Subscription data.
- All methods that would take several parameters with subscription information now simply accept a subscription.
Subscriptions are registered on the Session, so when an unsubscribe is
received, the subscription can be fetched from the Session. This allows
the subscription-remove functions to be greatly simplified.
The topic used internally for a Subscription can be changed by a listener
to be different from the topic the client subscribed to. This process is
completely transparent to the client.
- A TopicRewriter can be registered on the server to handle the topic rewriting.
- Subscription now has a topicInternal and a topicClient.
- For the client, messages sent to topicInternal appear to have been sent to topicClient.
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.

1 participant