对 Mosquitto MQTT 服务器进行分区

Partitioning a Mosquitto MQTT Server

我想在单个 MQTT 服务器上创建隔离环境。就像数据库服务器可以有多个模式并且 table 名称可以在不同的模式中重复。我想要一个 "MQTT schema",其中一个模式中的 topics/subscriptions 与另一个 "MQTT schema" 中的 topics/subscriptions 是隔离的,以便可以在不同的模式中使用相同的主题。如果可以在每个模式的基础上应用安全性,那就更好了,但这会要求很多。现在,我只是在寻找一种在同一台服务器上拥有隔离环境的方法——它可能需要每个模式一个单独的 TCP 端口来识别连接客户端的目标模式,因为协议本身没有任何概念架构。或者可以根据用户名或客户端 ID 将客户端映射到特定模式。

注意:我知道如何使用 ACL 来限制每个用户的主题访问。 ACL 不能解决这个问题。我不只是想限制主题访问,我想创建一个单独的环境,让用户可以自由地对主题做任何想做的事情,而无需我告诉他们他们不能使用哪些主题名称等。

只需使用 docker 容器 运行 mosquitto 并为每个 架构 启动新实例。将每个实例映射到单独的外部端口。完全隔离并且包括 auth 插件,您可以将安全性映射到单独的数据库 table,每个 schema 具有环境变量

另一个选项是 mount_point 配置选项,可以与 listener 声明一起使用 (man page)。

mount_point topic prefix

This option is used with the listener option to isolate groups of clients. When a client connects to a listener which uses this option, the string argument is attached to the start of all topics for this client. This prefix is removed when any messages are sent to the client. This means a client connected to a listener with mount point example can only see messages that are published in the topic hierarchy example and above.

此选项与另一个选项(docker 容器)之间的区别在于,您可以拥有一个没有挂载点的侦听器,可以查看所有不同分区的所有流量的侦听器声明。