find publisher id when subscriber subscribe to topic in mqtt

Internet of Things IoT Frameworks 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I am using mqtt in my nodejs backed application where there is communication with iot devices and where i am able to publish and subscribe to different topic.every thing is working well i can publish and subscribe to different topic. I am able to send client id or the publisher id who publish topic in message part which is a repeated task for every publisher. Is there any way we can know who is publisher while subscribing to topic. my mqtt client code at nodejs is var mqtt = require('mqtt') var url = "http://127.0.0.1:1883"; var client = mqtt.connect(url); client.on('connect', () => { console.log('Mqtt client connected to broker'); client.subscribe('status/open'); client.subscribe('status/close'); client.subscribe('sendMsg'); }) client.on('message', (topic, message) => { console.log('new topic received at controller', topic); console.log('new messge received at controller', message.toString()); ///is there any way to determine who is publishere here });

Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ No. This goes against one of the core principals of pub/sub messaging, which is that a publisher shouldn't care who is subscribed to a given topic and a subscriber shouldn't care where the data is coming from, it just subscribes to a topic. If you want to make it clear you have 2 options. Use a topic structure that encodes the publisher in the topic and the subscriber uses wildcard topics to receive data from all publishers. Encode the publisher information into the message payload.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Internet of Things Links

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community