LWT with user properties (timestamp): disconnect ungracefully

264 views Asked by At

MQTT newbie here

Developing on .NET with MqttNet library for EMQX broker:

I am using MQTTv5 feature 'user properties' to add a timestamp to my messages when published. That is working flawlessly.

However, I need to stamp the LWT messages too. In my connect method, I can supply an LWT including the timestamp user property. Now, when I subscribe to my LWT topic using MQQTX desktop client; I get those messages and LWTs; so far so good.

But when I terminate my programs process (by that, disconnect ungracefully); I immediately get an LWT message. The problem being that my 'timestamp' user property has the stamp from when the connection was established (and LWT first set).

I could leave the value empty in my connect-method, so empty value = ungraceful disconnect; but thats not very elegant

Is there a possibility to intercept LWT messages sent from the broker, and set the timestamp?

EDIT: I found the 'rules engine', it letting me use a broker-timestamp. But I could only add it to the payload so far (optimally it would be a user property) EMQ rule engine test

1

There are 1 answers

1
hardillb On

I don't think so, it would be up to the broker to set the timestamp as it is what actually publishes the LWT message when it notices the client has gone.

I don't believe there is anything at the MQTT spec level (I really need to re-read the v5 message properties stuff) to do that, but it might be something that could be done with an appropriate plugin in the broker if it supports such things.