gpt4 book ai didi

android - 用于 Android 聊天应用程序的 MQTT/限制主题访问

转载 作者:行者123 更新时间:2023-11-29 01:32:10 27 4
gpt4 key购买 nike

我正在尝试使用 MQTT 创建适用于 Android 的聊天应用程序,但有关如何操作的信息有限。

到目前为止,我已经设置了 MQTT 代理,但任何用户都可以收听和发布他们喜欢的任何主题(当然这不是聊天应用程序想要的)。

我使用 mosquitto 作为我的代理,它在其文档中列出了这组功能:

Topic access is added with lines of the format:

topic [read|write|readwrite] <topic>

It is also possible to define ACLs based on pattern substitution within the topic. The form is the same as for the topic keyword, but using pattern as the keyword.

pattern [read|write|readwrite] <topic>

The patterns available for substition are:

%c to match the client id of the client

%u to match the username of the client

The substitution pattern must be the only text for that level of hierarchy. Pattern ACLs apply to all users even if the "user" keyword has previously been given.

Example:

pattern write sensor/%u/data

Allow access for bridge connection messages:

pattern write $SYS/broker/connection/%c/state

到目前为止,我想做的事情如下: pattern readwrite chat/%u/msg

但这限制了每个用户在他们自己的主题上读/写,这不是预期的行为。

所以我的问题是:

有没有办法即时设置主题权限?

例如,在 A-B-C 之间的聊天中,如何确保只有 A-B-C 可以读写的 A-B-C 主题?

最佳答案

不使用 ACL 文件,但 mosquitto 支持 ACL 的插件系统

例如https://github.com/jpmens/mosquitto-auth-plug/

这允许您将 ACL 存储在可以动态更新的数据库中

关于android - 用于 Android 聊天应用程序的 MQTT/限制主题访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30569812/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com