Skip to content

Feature/topic rewriting#932

Draft
hylkevds wants to merge 1 commit into
moquette-io:mainfrom
FraunhoferIOSB:feature/topic_rewriting
Draft

Feature/topic rewriting#932
hylkevds wants to merge 1 commit into
moquette-io:mainfrom
FraunhoferIOSB:feature/topic_rewriting

Conversation

@hylkevds
Copy link
Copy Markdown
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 hylkevds force-pushed the feature/topic_rewriting branch 3 times, most recently from e5d67fc to 87fb200 Compare March 22, 2026 15:56
@hylkevds hylkevds force-pushed the feature/topic_rewriting branch from 87fb200 to 72ccb6c Compare April 17, 2026 09:25
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.
@hylkevds hylkevds force-pushed the feature/topic_rewriting branch from 72ccb6c to 56bca23 Compare May 15, 2026 09:00
@hylkevds hylkevds requested a review from andsel May 15, 2026 09:14
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