简体   繁体   English

emqx MQTT broker 重启后不存在 session

[英]emqx MQTT broker doesn’t persist session after restart

I'm using emqx broker and I want to persist session on disk so that I can recover sessions if the broker reboot for any reasons.我正在使用 emqx 代理,我想将 session 保存在磁盘上,以便在代理因任何原因重新启动时可以恢复会话。

What I do:我所做的:

  • start the emqx broker with a docker-compose:使用 docker-compose 启动 emqx 代理:
emqx1:
    image: emqx/emqx:v4.0.0
    environment:
      - EMQX_NAME=emqx
      - EMQX_NODE__NAME=emqx.local.node
      - EMQX_HOST=node1.emqx.io
      - EMQX_CLUSTER__DISCOVERY=static
      - EMQX_RETAINER__STORAGE_TYPE=disc
    volumes:
      - emqx-data:/opt/emqx/data
      - emqx-etc:/opt/emqx/etc
      - emqx-log:/opt/emqx/log
    ports:
      - 18083:18083
      - 1883:1883
      - 8081:8081
    networks:
      gateway-api:
        aliases:
        - node1.emqx.io
  • start a Go subscribe client with Paho MQTT lib with following config.使用 Paho MQTT 库启动 Go 订阅客户端,配置如下。 The code of the client can be found in the "stdinpub" and "stdoutsub" folder in the paho repo客户端的代码可以在paho repo的“stdinpub”和“stdoutsub”文件夹中找到
clientId = "sub1"
qos = 1
clean = false
topic_subscribe = "topic1"
  • start a Go publish client with this config and publish a message:使用此配置启动 Go 发布客户端并发布消息:
clientId = ""
clean = true

and the message:和消息:

qos = 1
retain = false
topic = "topic1"
payload = "test"
  • then I disconnect the client "sub1" and send a 2nd message with qos=1:然后我断开客户端“sub1”并使用 qos=1 发送第二条消息:
qos = 1
retain = false
topic = "topic1"
payload = "test2"

this message is not delivered to the client "sub1" so the broker queues it (qos=1).此消息未传递到客户端“sub1”,因此代理将其排队(qos=1)。 Indeed if I restart the sub1 client it does get the message "test2".事实上,如果我重新启动 sub1 客户端,它确实会收到消息“test2”。
But if I reboot the broker before restarting the client "sub1", then "test2" get lost and is not delivered.但是,如果我在重新启动客户端“sub1”之前重新启动代理,那么“test2”会丢失并且不会被传递。

I tried the same test with retain set to true and the message "test2" is well delivered even after the broker is rebooted.我尝试了相同的测试, retain设置为true ,即使在代理重新启动后,消息“test2”也能很好地传递。 So the broker persist the retained messages on disk well but not the client session.因此,代理将保留的消息保存在磁盘上,但客户端 session 没有。

Any idea of why?知道为什么吗? Is there a configuration I should change to persist client session on disk?我应该更改配置以将客户端 session 持久保存在磁盘上吗?

As hashed out in the comments.正如评论中所说的那样。

Client Session storage is a feature only available in the "Enterpise" paid for version of emqx not the free to use version.客户端 Session 存储是 emqx 付费版而不是免费版的“企业版”才有的功能。

This can be seen from the Feature list and the issues 1 & 2 also asking about the feature.这可以从功能列表中看出,问题12也询问了该功能。

retainer message storage in disk:磁盘中的保留消息存储:

# etc/plugins/emqx_retainer.conf

## Where to store the retained messages.
retainer.storage_type = disc_only

The EMQ X open source product does not support the persistence of messages within the server, which is an architectural design choice. EMQ X 开源产品不支持消息在服务器内部的持久化,这是一种架构设计的选择。 First of all, the core problem solved by EMQ X is connection and routing;首先,EMQ X 解决的核心问题是连接和路由; secondly, we believe that built-in persistence is a wrong design.其次,我们认为内置持久性是错误的设计。

Traditional MQ servers with built-in message persistence, such as the widely used JMS server ActiveMQ, are redesigning the persistence part in almost every major version.具有内置消息持久性的传统 MQ 服务器,例如广泛使用的 JMS 服务器 ActiveMQ,几乎在每个主要版本中都在重新设计持久性部分。 There are two problems with the design of built-in message persistence:内置消息持久化的设计有两个问题:

How to balance the use of memory and disk? memory和磁盘如何平衡使用? Message routing is memory-based, while message storage is disk-based.消息路由是基于内存的,而消息存储是基于磁盘的。 Under the multi-server distributed cluster architecture, how to place the Queue and how to replicate the messages of the Queue?多服务器分布式集群架构下,如何放置Queue,如何复制Queue的消息? Kafka has made the correct design for the above problems: a message server based entirely on disk distributed Commit Log. Kafka针对上述问题做出了正确的设计:完全基于磁盘分布式Commit Log的消息服务器。

After EMQ X separates message routing and message storage responsibilities in design, data replication, disaster recovery backup and even application integration can be implemented flexibly at the data level. EMQ X 在设计上将消息路由和消息存储职责分离后,可以在数据层面灵活实现数据复制、容灾备份甚至应用集成。

In EMQ X Enterprise Edition products, you can persist messages to databases such as Redis, MongoDB, Cassandra, MySQL, PostgreSQL, and message queues such as RabbitMQ and Kafka through a rule engine or plug-in. In EMQ X Enterprise Edition products, you can persist messages to databases such as Redis, MongoDB, Cassandra, MySQL, PostgreSQL, and message queues such as RabbitMQ and Kafka through a rule engine or plug-in.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM