0

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

Master Azazel
  • 612
  • 1
  • 12
  • 32

1 Answers1

1

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.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • thanks for your answer. I found the 'rules engine' for the EMQ broker; it lets me intercept a message with given payload e.g. 'ungraceful disconnect' and lets me republish with a broker set timestamp. only thing I haven't found out is how to access the user properties within the rule; its added to the payload by default – Master Azazel Dec 14 '21 at 15:02