Skip to content

Request support of MQTT Last Will and Testament (LWT) #56

@ftylitak

Description

@ftylitak

Issue

Since the introduction of the mproxy in Mainflux (and now Magistrala), it lacks support of listening MQTT Last Will messages from MQTT broker.

Case

We have the case of devices reporting connection status everytime the connect/disconnect to the network through a simple MQTT publish. To cover edge cases of devices that are forcefully unplugged from the power, we also setup Last Will on every connection to report that the device is disconnected if not properly terminated.

This worked perfectly with Mainflux 0.10.0 that we have been using for a while, though after upgrading to mainflux 0.12.0 that has been using mproxy, these messages we not received.

Investigation results

After investigating the source code of mproxy, we ended up to two keypoints that prevent this feature to function with the current mproxy architecture.

a) at the two streams of each session, only messages comming from client to the broker are notified (passed onto nats). (

if dir == Up {
)

b) the Last Will messages are generated from the MQTT broker only if there are active subscribers at that time. Since the mproxy is only packet forwarer, it is not a subscriber so in the general case, those messages are never generated.

Our workaround

To restore the functionality in our deployment:

a) when a publish message has been received we added a hardcoded check whether the suffix of the topic matches "/connectionStatus" that we use, to call notify regardless the stream direction

b) added dummy subscribers listening to those messages, to force MQTT broker to generate Last Wills when needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationquestionFurther information is requestedwontfixThis will not be worked on

    Type

    No type

    Projects

    Status

    ⛏ Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions