VerneMQ single publish messages lost when client is offline

Tags: , , ,



I am quite new to MQTT and brokers, but I am having an issue with VerneMQ not sending offline messages to clients. Here is my setup. I have a backend written in Python which is using the Paho Eclipse MQTT library’s single() method to send messages to a connected client. The client, a virtual machine on my development station, has a client which is written in go-lang, using paho.mqtt.golang to connect to the broker and subscribe.

The call to single() on the backend looks like this:

def send_message(device_id, payload):
    token = get_jwt('my_token').decode()
    mqtt.single(
       f'commands/{device_id}',
       payload=payload,
       qos=2,
       hostname=MESSAGING_HOST,
       port=8080,
       client_id='client_id',
       auth={'username': 'username', 'password': f'Bearer {token}'},
       transport='websockets'
   )

On the client, the session is established with the following options:

func startListenerRun(cmd *cobra.Command, args []string) {
//mqtt.DEBUG = log.New(os.Stdout, "", 0)
mqtt.ERROR = log.New(os.Stdout, "", 0)
opts := mqtt.NewClientOptions().AddBroker(utils.GetMessagingHost()).SetClientID(utils.GetClientId())
opts.SetKeepAlive(20 * time.Second)
opts.SetDefaultPublishHandler(f)
opts.SetPingTimeout(5 * time.Second)
opts.SetCredentialsProvider(credentialsProvider)
opts.SetConnectRetry(false)
opts.SetAutoReconnect(true)
opts.willQos=2
opts.SetCleanSession(false)

I am not showing all the code, but hopefully enough to illustrate how the session is being set up.

I am running VerneMQ as a docker container. We are using the following environment variables to change configuration defaults in the Dockerfile:

ENV DOCKER_VERNEMQ_PLUGINS.vmq_diversity on
ENV DOCKER_VERNEMQ_VMQ_DIVERSITY.myscript1.file /etc/vernemq/authentication.lua
ENV DOCKER_VERNEMQ_VMQ_ACL.acl_file /etc/vernemq/vmq.acl
ENV DOCKER_VERNEMQ_PLUGINS.vmq_acl on
ENV DOCKER_VERNEMQ_RETRY_INTERVAL=3000

As long as the client has an active connection to the broker, the server’s published messages arrive seamlessly. However, if I manually close the client’s connection to the broker, and then publish a message on the backend to that client, when the client’s connection reopens, the message is not resent by the broker. As I said, I am new to MQTT, so I may need to configure additional options, but so far I’ve yet to determine which. Can anyone shed any light on what might be happening on my setup that would cause offline messages to not be sent? Thanks for any information.

Answer

As thrashed out in the comments

Messages will only be queued for an offline client that has subscribed at greater than QOS 0

More details can be found here



Source: stackoverflow