1

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.

What I do:

  • start the emqx broker with a docker-compose:
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. The code of the client can be found in the "stdinpub" and "stdoutsub" folder in the paho repo
clientId = "sub1"
qos = 1
clean = false
topic_subscribe = "topic1"
  • start a Go publish client with this config and publish a message:
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:
qos = 1
retain = false
topic = "topic1"
payload = "test2"

this message is not delivered to the client "sub1" so the broker queues it (qos=1). Indeed if I restart the sub1 client it does get the message "test2".
But if I reboot the broker before restarting the client "sub1", then "test2" get lost and is not delivered.

I tried the same test with retain set to true and the message "test2" is well delivered even after the broker is rebooted. So the broker persist the retained messages on disk well but not the client session.

Any idea of why ? Is there a configuration I should change to persist client session on disk ?

hardillb
  • 54,545
  • 11
  • 67
  • 105
cylon86
  • 550
  • 4
  • 20
  • The retained flag has nothing to do queuing messages for offline clients with a persistent session and a subscription at QOS >= 1, do not conflate the two. You should reffer to the messages as queued, not retained. – hardillb Jun 04 '21 at 16:00
  • Also a quick look at the docs, suggests that client session persistence may be a Enterprise feature, not available in the basic version of the broker. – hardillb Jun 04 '21 at 16:06
  • @hardillb thx for correction on the vocabulary, I updated my post. Can link the doc where it says it is in the paid plan ? I can't find it – cylon86 Jun 04 '21 at 16:30
  • It's more that there are no config options listed in the docs for the free version yet there are options to configure multiple sessions storage options in the pro docs – hardillb Jun 04 '21 at 17:40
  • @cylon86 see the [Features List](https://docs.emqx.io/en/broker/v4.3/introduction/checklist.html#function-of-enterprise-version) - the feature you are looking for is "Data persistence". There are also a number of issues (e.g. [1](https://github.com/emqx/emqx/issues/2126), [2](https://github.com/emqx/emqx/issues/1481)) from users with the same question. – Brits Jun 04 '21 at 20:57
  • Thx for your help, it is indeed in the entreprise version then. They should make this limitation more explicit (like having an explicit data_persistence parameter in the config that throw an error if you don't have the paid plan) – cylon86 Jun 06 '21 at 15:58

2 Answers2

0

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.

This can be seen from the Feature list and the issues 1 & 2 also asking about the feature.

hardillb
  • 54,545
  • 11
  • 67
  • 105
-1

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. First of all, the core problem solved by EMQ X is connection and routing; 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. There are two problems with the design of built-in message persistence:

How to balance the use of memory and disk? 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? Kafka has made the correct design for the above problems: a message server based entirely on disk distributed 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.

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.

wivwiv
  • 255
  • 1
  • 3
  • As mentioned in the comments under the question, this has NOTHING to do with retained messages, it is to do with client session storage. – hardillb Jul 07 '21 at 07:23