eclipse-ditto / ditto

Eclipse Ditto™: Digital Twin framework of Eclipse IoT - main repository
https://eclipse.dev/ditto/
Eclipse Public License 2.0
689 stars 224 forks source link

MQTT Last Will Placeholders to support Eclipse Sparkplug #1995

Closed pedro-nicolau-carvalho closed 1 month ago

pedro-nicolau-carvalho commented 2 months ago

Hello,

I'm trying to integrate Eclipse Ditto with Eclipse Sparkplug, and I've been mostly successful in all the message types and flows:

{
   "online": boolean
   "timestamp: milis since epoc - this timestamp is always the timestamp of when the connection is started, so a correlation betwen online/offline states can be made
}

Only one small detail is missing to support Eclipse Sparkplug in this last point. When eclipse ditto ungracefully disconnects from the MQTT broker, a last will message should be sent with the status and the timestamp. Since the last will connection configuration is static, the timestamp cannot be rightfully set.

Does it make sense for Eclipse Ditto to support placeholders in the last will message? Also, the issue still remains that the timestamp should be the same as the last connection opened announcement. Could a connection-specific placeholder exist which holds the value of when the connection opens or closes?

It seems to me at least that an integration between these two projects is fruitful since they both act under the same domain and under the Eclipse umbrella.

Thank you.

thjaeckle commented 2 months ago

Hi.

Very interesting, would be nice to read about a finished Sparkplug integration at some point.

Hm, if I understood Mqtt last will correctly, providing a dynamic payload to it won't work. I understood that a client defines this last will message eg after first connection. Then, when the broker detects that the client is gone, it will publish the (previously defined) last will message to subscribers. So Ditto has no chance to provide a dynamic payload.

I'm not an mqtt expert, but maybe the last will message could be refreshed/updated periodically, eg each minute? This could be something Ditto could handle.

pedro-nicolau-carvalho commented 2 months ago

Hello @thjaeckle,

Yes you're right, the will message is sent along with the connect packet, which I assume happens before the ConnectionOpennedAnnouncement eclipse ditto message. So I guess that won't work...

I guess a really dirty workaround (😄) would be to use an http push connection that listens to closed connection announcements and updates the last will message and javascript mappers with new timestamps. Have you seen approaches like these, that use http push connections that update ditto entities? Any opinions?

Thank you for the help!

thjaeckle commented 1 month ago

@pedro-nicolau-carvalho sorry for the late reply

Have you seen approaches like these, that use http push connections that update ditto entities? Any opinions?

No, I did not see approaches like there - I would also not suggest to build such a "recursion" (Ditto invoking Ditto :D). A lot things could go wrong here I assume ..