How to Define and Use Variable Values in a Topic Namespace

Satyam Chauhan 567 Reputation points
2024-11-11T09:44:45.5+00:00

Hi,

I am using azure event grid namespace mqtt broker. The broker has topic spaces configured. I want the topic template to support variable which can be replaced by client while publishing.

For example,

The topic template should be something like this - myhome/{roomname}/{sensorid}, here roomname and sensorid should be dynamic based on the value provided by client.

Let's say client1 is publishing some payload to topic - "myhome/livingroom/009"

and client2 is publishing to topic - "myhome/bedroom/001"

and client3 is subscribing to topic - "myhome/livingroom/009", then client3 should only receive messages from "myhome/livingroom/009" and not from any other topics.

Please help how should I create such topic templates and how to utilize these templates while publishing and subscribing.

I am developing in .NET using mqttnet package.

Thanks

Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
397 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde | MVP 33,231 Reputation points MVP
    2024-11-11T18:31:13.67+00:00

    Hello @Satyam Chauhan,

    welcome to this moderated Azure community forum.

    Can you check out this part of the documentation?

    Topic templates support MQTT wildcards (+ and #) and the following variables: ${client.attributes.x}: this variable represents an assigned attribute to a client during client creation/update, such as "x" would be equal to the exact string of the attribute key

    An example seen there is:

    area/${client.attributes.area}/telemetry
    
    

    If you want to limit access to certain topics, you probably need to add the 'client.authenticationName' name too in the topics (either for publishing or subscribing).


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.