eclipse / tahu

Eclipse Tahu addresses the existence of legacy SCADA/DCS/ICS protocols and infrastructures and provides a much-needed definition of how best to apply MQTT into these existing industrial operational environments.
https://eclipse.org/tahu
Eclipse Public License 2.0
221 stars 129 forks source link

Mqtt client optional teardown #365

Closed ferm10n closed 6 months ago

ferm10n commented 7 months ago

This is a follow-up to https://github.com/eclipse/tahu/pull/341, which adds the ability to pass an existing mqtt client to a sparkplug client. This was done to allow multiple sparkplug clients to share the same mqtt client.

An unintended side affect was that when a sparkplug client is terminated with .stop(), the mqtt client is also terminated. This meant that all other sparkplug clients using this mqtt client would suddenly stop working.

This PR addresses this issue by only ending the mqtt client if it was created by the sparkplug client. The expectation is that an external mqtt client's lifecycle would be managed elsewhere.

Additionally, I noticed the non-null assertions on this.client were no longer needed and I removed them. This should be fine because the client is always set in the constructor.