Use a Uuid for the mqtt client ID

This commit is contained in:
QuantumEntangledAndy committed 2024-05-05 11:08:58 +07:00
1 parent e53b0f09d2
commit ab947b895c
3 files changed
+5 -2

No files matched your search

Generated
+1
View File
@@ -1582,6 +1582,7 @@ dependencies = [
"tokio-stream",
"tokio-util",
"toml",
"uuid",
"validator 0.17.0",
"validator_derive 0.17.0",
]
+1
View File
@@ -41,6 +41,7 @@ tokio = { version = "1.27.0", features = ["rt-multi-thread", "macros", "io-util"
tokio-stream = "0.1.12"
tokio-util = { version = "0.7.7", features = ["full", "tracing"] }
toml = "0.8.2"
uuid = { version = "1.8.0", features = ["v4"] }
validator = "0.17.0"
validator_derive = "0.17.0"
+3 -2
View File
@@ -22,6 +22,7 @@ use tokio::{
};
use tokio_stream::{wrappers::BroadcastStream, StreamExt};
use tokio_util::sync::CancellationToken;
use uuid::Uuid;
pub(crate) struct Mqtt {
cancel: CancellationToken,
@@ -125,7 +126,7 @@ impl<'a> MqttBackend<'a> {
async fn run(&mut self) -> AnyResult<()> {
log::trace!("Run MQTT Server");
let mut mqttoptions = MqttOptions::new(
"Neolink".to_string(),
format!("Neolink{}", Uuid::new_v4()),
&self.config.broker_addr,
self.config.port,
);
@@ -519,7 +520,7 @@ impl LastWillMqtt {
) -> AnyResult<Self> {
log::trace!("Run MQTT Last Will");
let mut mqttoptions = MqttOptions::new(
format!("NeolinkLastWill_{}", topic),
format!("NeolinkLastWill_{}_{}", topic, Uuid::new_v4()),
&config.broker_addr,
config.port,
);