volantmq:实践指南

作者:袖梨 2026-09-10

真正理解volantmq,要从它处理的任务开始:高性能 MQTT 服务器。实际做部署与运行环境时,经常会碰到权限、依赖和环境差异会放大维护成本,所以功能列表并不能代替验证。试跑可以从在非生产环境复现一次安装与运行开始,并把依赖锁定、权限边界、日志、回滚和资源消耗写进验收记录。如果团队属于愿意维护环境并重视故障恢复的工程团队,它有继续测试的理由;否则先看替代方案会更省时间。

VolantMQ

*VolantMQ 图片由 Marina Troian 拍摄,根据 [知识共享署名 4.0 国际许可][cc-by] 获得许可

VolantMQ 是一款高性能 MQTT 经纪商,旨在完全符合 MQTT 规范

##Features MQTT Specs

  • MQTT v3.1 - V3.1.1 全面支持
  • MQTT V5.0 有限支持。请参阅下面的详细信息
    • [x] 属性
    • [x] 发布过期
    • [x] 会话过期
    • [ ] 共享主题
    • [x] 订阅ID
    • [x] 订阅选项
    • [ ] 增强认证
    • [x] 主题别名
    • [x] 服务器断开连接
    • [x] 流量控制
    • [x] 最大数据包大小
    • [x] 服务器保持活动状态
    • [x] 已分配 ClientID

网络传输

  • [x] TCP
  • [x] TLS
  • [x] WebSocket
  • [x] WebSocket+TLS

坚持

默认情况下,服务器以内存持久性启动,这意味着服务器重新启动后所有会话和消息都会丢失。

插件

授权

  • [x] 服务器内置基本 auth.Key- 值对,格式为 user: sha256 of password,由以下任一选项提供

    • 配置文件中的用户及其密码哈希值
      - name: internal  # authenticator name, used by listeners
        backend: simpleAuth # authenticator type
        config:
          users:
            testuser: "9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05" # testpassword
    
    • 用户及其密码哈希值位于单独的文件中
      - name: internal  # authenticator name, used by listeners
        backend: simpleAuth # authenticator type
        config:
          users: # both can be used simultaneously
            testuser: "9f735e0df9a1ddc702bf0a1a7b83033f9f7153a00c29de82cedadc9957289b05" # testpassword
          usersFile: <some path>
    
  • [x] HTTP

监控

  • [x] 系统树
  • [x] 普罗米修斯
    • [x] Grafana 仪表板。致谢 奥列格·别列茨基
    • [x] Kubernetes 的服务监视器。致谢 奥列格·别列茨基

坚持

  • [x] 内置内存服务器
  • [x] BBolt

调试

  • [x] PProf

健康

  • [x] 健康

配置

服务器以 的默认配置启动,此处为。任何进一步的配置应用在顶部

环境变量

  • VOLANTMQ_CONFIG - 本节 中描述的配置文件的路径。
  • VOLANTMQ_PLUGIN_AUTH_HTTP_<NAME>_TOKEN - 用于身份验证插件的 API 令牌 例如,要从下面的配置向身份验证插件 http1 提供身份验证令牌,变量应声明为 VOLANTMQ_PLUGIN_AUTH_HTTP_HTTP1_TOKEN

配置文件

文件分为几个部分 完整的示例可以在这里找到 here

系统

system:
  log:
    console:
      level: info # available levels: debug, info, warn, error, dpanic, panic, fatal
  http:
    defaultPort: 8080 # default HTTP listener assigned. Assigned to plugins like debug/health/metrics if they dont specify own port

插件

plugins:
    enabled: # list of plugins server will load on startup
      - systree
      - prometheus
      - debug
      - health
      - auth_http
      - persistence_bbolt
    config: # configuration of each plugin
      <plugin type>:
        - backed: systree # plugin name, allowed: systree, prometheus, http, prof.profiler, health, bbolt
          name: http1     # required by auth plugins only. Value used in auth.order
          config:         # configuration passed to plugin on load stage. refer to particular plugin for configuration

默认身份验证配置

auth:
  order: # default auth order. Authenticators invoked in the order they present in the config. Listener can override
    - internal

MQTT 规格

mqtt:
  version: // list of supported MQTT specifications
    - v3.1.1
    - v5.0
  keepAlive:
    period: 60 # KeepAlive The number of seconds to keep the connection live if there's no data.
    # Default is 60 seconds
    force: false # Force connection to use server keep alive interval (MQTT 5.0 only)
    # Default is false
  options:
    connectTimeout: 10 # The number of seconds to wait for the CONNACK message before disconnecting.
    # If not set then default to 2 seconds.
    offlineQoS0: true # OfflineQoS0 tell server to either persist (true) or not persist (false) QoS 0 messages for non-clean sessions
    # If not set than default is false
    sessionPreempt: true # AllowDuplicates Either allow or deny replacing of existing session if there new client with same clientID
    # If not set than default is false
    retainAvail: true # don't set to use default
    subsOverlap: false # tells server how to handle overlapping subscriptions from within one client
                       # - true server will send only one publish with max subscribed QoS even there are n subscriptions
                       # - false server will send as many publishes as amount of subscriptions matching publish topic exists
                       # Default is false
    subsId: false # don't set to use default
    subsShared: false # don't set to use default
    subsWildcard: true # don't set to use default
    receiveMax: 65535 # don't set to use default
    maxPacketSize: 268435455 # don't set to use default
    maxTopicAlias: 65535 # don't set to use default
    maxQoS: 2

听众

listeners:
  defaultAddr: "0.0.0.0" # default 127.0.0.1
  mqtt: # there are two types of listeners allowed tcp and ws (aka WebSocket) 
    tcp:
      1883:                # port number. can be as many ports configurations as needed
        host: 127.0.0.1    # optional. listen address. defaultAddr is used if omitted
        auth:              # optional. default auth configuration is used if omitted
          order:           # optional. default auth configuration is used if omitted
            - internal
      1884:
        auth:
          order:
            - http1
        tls:               # TLS configuration
          cert:            # path to certificate file
          key:             # path to key file
    ws:
      8883:
        path: mqtt
        auth:
          order:
            - http1
      8884:
        path: mqtt
        auth:
          order:
            - http1
        tls:               # TLS configuration
          cert:            # path to certificate file
          key:             # path to key file

拥有多个侦听器的原因来自 TLS 以及身份验证的性能影响 系统内部用户可以省略整个身份验证和 TLS

   ┌──────────────┐                                
   │              │                                
   │ MQTT process │                                
   │              │                                
   └───────▲──────┘                                
           │                                       
           │             ╔════════════════════════╗
           │             ║ VolantMQ               ║
           │             ║                        ║
      ╔════▼═══╗         ║                        ║
      ║intranet◀═════════▶ 1883  # no auth, no TLS║
      ╚════════╝         ║                        ║
      ╔════════╗         ║                        ║
      ║internet◀═════════▶ 1884  # auth and TLS   ║
      ╚═▲══▲══▲╝         ║                        ║
        │  │  │          ╚════════════════════════╝
        │  │  │                                    
   ┌────┘  │  └───┐                                
   │       │      │                                
   │       │      │                                
   │       │      │                                
┌──▼─┐  ┌──▼─┐  ┌─▼──┐                             
│IoT1│  │IoT2│  │IoTn│                             
└────┘  └────┘  └────┘                             

分布

  • [x] Docker 映像包含此[部分][#Plugins]中列出的预构建插件
  • [ ] 头盔

How to use

docker run --rm -p 1883:1883 -p 8080:8080 -v $(pwd)/examples/config.yaml:/etc/volantmq/config.yaml 
--env VOLANTMQ_CONFIG=/etc/volantmq/config.yaml volantmq/volantmq

相关文章

精彩推荐