I've noticed that it's theoretically possible to subscribe to a topic and only receive messages that have a specific JSON payload (For example, device id), but I cannot find how to do it. How exactly does it happen on the client side(mqtt.js or mqttx for testing)? What options should I include when I subscribe? Is there a specific setting that I need to enable for the broker(I am using mosquitto).
From: Content-Type alternative in MQTT
What I'm looking for as an answer is more concrete example than upper link
I know that this can be done with different topics.Unfortunately I don`t have access to how messages are publish(one topic with device id in the payload). I am trying to filter unnecessary on broker level(mosquitto).
What you describe in the first paragraph is not possible.
The only filter that the client can send to the broker is the topic pattern (in MQTTv5 you can tell the broker to filter out messages published by the same client to prevent receiving your own message).
If you want to filter on payload you have to implement that yourself client side after the message has been delivered.
What is described in the answer to the other question is just a hint to the format of the payload, it does not offer any filtering.