Can an MQTT broker be configured not to echo messages on a topic?

半腔热情 提交于 2020-06-28 02:01:28

问题


If an mqtt client publishes to and subscribes to a topic, is it possible to convince the broker not to echo message sent by the client back to the client that published the message?

For example, if there are four clients (A, B, C, D) that are subscribed to and publishing to topic "foo", and client A publishes a message, I would like the message to be received by clients B, C, and D, but not echoed back to client A.


回答1:


The MQTT protocol provides publish/subscribe pattern so every topic you subscribed, you receive messages sent on it. The MQTT broker implementation isn't fully standardized : brokers can be different due to different supported features. Until today I didn't head about a broker with such a feature. Of course it could be possible to implement but it depends on broker developers.

Paolo.




回答2:


In the MQTT protocol specifications, section 3.8 SUBSCRIBE - Subscribe to topics, the document says (emphasis mine):

The SUBSCRIBE Packet is sent from the Client to the Server to create one or more Subscriptions. Each Subscription registers a Client’s interest in one or more Topics. The Server sends PUBLISH Packets to the Client in order to forward Application Messages that were published to Topics that match these Subscriptions.

So you will receive the packet back. I think you may implement some sort of ACL to topics to reach your desired behaviour but this would be broker specific.
Another solution is to rethink your topic structure.




回答3:


As stated before you cannot achieve message level authorization with the MQTT protocol itself.

But it is possible to achieve this kind of functionality within some specific Brokers' functionalities.

For example with ActiveMQ you can implement your own class to the interface MessageAuthorizationPolicy with the method isAllowedToConsume(ConnectionContext context, Message message)

Here you can see one example of RedHat Fuse ESB (which uses ActiveMQ): MessageLevelAuth



来源:https://stackoverflow.com/questions/29737076/can-an-mqtt-broker-be-configured-not-to-echo-messages-on-a-topic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!