问题
Is it possible to that two clients are subscribed to same topic in MQTT broker. And based on authorization, some of the massages are sent to one client and not other (subscribed on same topic).
回答1:
No
Any number of clients can be subscribed to a given topic, but you can not limit which of those clients can receive messages on that topic on a per message basis. It is all the topic or none.
回答2:
There is no direct solution for this approach. But however I have a workaround for this solution.
Say you have two client with ClientId: 1 and 2
Say your topic structure is : stackoverflow/data/{Client-ID}/sensor/ingress
While defining the authorization parameter you can assert with the permission as +/+/{Client-ID}/+/+
This will make sure that, the topic structure will remain the same, but at the same time, the client will be able to publish and subscribe data only from their own topics.(topics which have their client-Id).
来源:https://stackoverflow.com/questions/47014071/sending-message-to-some-of-the-clients-subscribed-on-same-topic-in-mqtt