From 5add0f34c3df93190e377e34a04140374f31a664 Mon Sep 17 00:00:00 2001 From: akn Date: Wed, 21 Oct 2026 15:55:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E8=BF=9E=E5=90=8E=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E8=AE=A2=E9=98=85=20notify/#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 17115e5..7186c40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -182,10 +182,6 @@ async fn run_mqtt(pool: SqlitePool, tx: broadcast::Sender) { let (client, mut eventloop) = AsyncClient::new(opts, 100); - client.subscribe("notify/#", QoS::AtMostOnce).await.unwrap(); - - info!("MQTT subscribed to notify/#"); - let pool_clone = pool.clone(); let tx_clone = tx.clone(); @@ -214,6 +210,11 @@ async fn run_mqtt(pool: SqlitePool, tx: broadcast::Sender) { } Ok(rumqttc::Event::Incoming(Packet::ConnAck(_))) => { info!("MQTT connected"); + // clean_session=true 会在断线后丢弃订阅,重连时必须重新订阅 + match client.subscribe("notify/#", QoS::AtMostOnce).await { + Ok(_) => info!("MQTT subscribed to notify/#"), + Err(e) => error!("MQTT subscribe failed: {e}"), + } } Ok(_) => {} Err(e) => {