Skip to content

Commit 95a1080

Browse files
committed
Switch to using UUIDs to name different MQTT clients
1 parent 3bf499f commit 95a1080

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ serde_json = "1.0.137"
2929
paho-mqtt = {version = "0.13.0", default-features=false, features=["bundled", "ssl"]}
3030
async-trait = "0.1.85"
3131
async-once-cell = "0.5.4"
32-
random = "0.14.0"
33-
rand = "0.8.5"
3432
tracing = {version = "0.1.41", features = ["attributes", "std", "tracing-attributes", "async-await"]}
3533
tracing-subscriber = {version="0.3.19", features=["env-filter", "fmt"]}
34+
uuid = {version = "1.12.1", features = [
35+
"v4", # Lets you generate random UUIDs
36+
"fast-rng", # Use a faster (but still sufficiently random) RNG
37+
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
38+
]}
3639

3740
[features]
3841
ros = ["dep:r2r"]

src/mqtt_client.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use async_stream::stream;
44
use futures::{stream::BoxStream, StreamExt};
55
use paho_mqtt::{self as mqtt, Message};
66
use tracing::{debug, info, instrument, warn, Level};
7+
use uuid::Uuid;
78

89
type Hostname = String;
910

@@ -45,7 +46,7 @@ pub async fn provide_mqtt_client_with_subscription(
4546
.server_uri(hostname.clone())
4647
.client_id(format!(
4748
"robosapiens_trustworthiness_checker_{}",
48-
rand::random::<u16>()
49+
Uuid::new_v4()
4950
))
5051
.finalize();
5152

@@ -87,7 +88,7 @@ pub async fn provide_mqtt_client(hostname: Hostname) -> Result<mqtt::AsyncClient
8788
.server_uri(hostname.clone())
8889
.client_id(format!(
8990
"robosapiens_trustworthiness_checker_{}",
90-
rand::random::<u16>()
91+
Uuid::new_v4()
9192
))
9293
.finalize();
9394

0 commit comments

Comments
 (0)