Reputation: 21
I have written an angularjs application. There is a form where users can type in notes. The application uses a specific mqtt topic like "app/form/notes". The paho js client in this app publish and subscribe to the same topic. If a user is typing in somthing, the onchange event occurs and publish the new value to the topic.
Now the client is receiving the message which he was sending to the broker, because he is subscribed to this topic. But the received message is useless, because the value is the same. What is the best way to handle this problem?
Upvotes: 2
Views: 7627
Reputation: 325
If you find that you are subscribing to the same channel you are publishing to, there may be something you can do to your topic structure to make that not so. For example, if you follow the semantic MQTT topic naming suggested in this post: http://tinkerman.cat/mqtt-topic-naming-convention/ you will find a lot of these types of issues go away. If you are a temperature sensor, you care about publishing your temperature, not subscribing to it.
If you are already semantically named, and you have a chatty topic that a lot of players are pub'ing and sub'ing to, some brokers will add the publisher to the MQTT message automatically, and if they do not, add it to the payload. This obviously makes it easy to spoof, so do not rely on that publisher identity being correct for any sensitive transactions.
Upvotes: 4
Reputation: 59628
Include a client id with in the message so when a message arrives it can easily be identified as having originated locally and can be ignored.
e.g.
{
'source': 'client1',
'payload': 'asdfghjklqwertyuiop...'
}
Upvotes: 2