fix: 重连后重新订阅 notify/#
This commit is contained in:
1 parent
8df639ac4b
commit
5add0f34c3
1 file changed
+5
-4
+5
-4
@@ -182,10 +182,6 @@ async fn run_mqtt(pool: SqlitePool, tx: broadcast::Sender<String>) {
|
||||
|
||||
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<String>) {
|
||||
}
|
||||
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) => {
|
||||
|
||||
Reference in new issue
Block a user