Naturally, we need a way to configure the MQTT connection parameters (host, port, username, etc.). For that, we'll use a TOML configuration file, which is read at startup and deserialized into a structure owned by the Session. The Session object now has a `run` method, which establishes the MQTT connection and then repeatedly waits for messages from the broker. It will continuously attempt to connect to the broker until it succeeds. This way, if the broker is unavailable when the application starts, it will eventually connect when it becomes available. Once the initial connection is established, the client will automatically reconnect if it gets disconnected later. Since the `run` method loops forever and never returns, we need to use a separate Tokio task to manage it. We keep the task handle so we can cancel the task when the application shuts down.
3 lines
21 B
Plaintext
3 lines
21 B
Plaintext
/target
|
|
/config.toml
|