-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mqtt v5 subscriber disconnect problem #195
Comments
What server are you using? Is it public or private? If it's a public server, consider changing you Client ID to something unique. Someone else might be connecting with the same ID and knocking you off the server. Is there a chance that the server is dropping you? Maybe monitor for a disconnect message from the server - perhaps using Is there any chance your board (computer) is powering down or going to sleep? Does it reconnect? |
The server I am using is EMQX 5.0 and I am sure that my client id is unique. I'm not running on my laptop, I'm running on a small machine with ubuntu installed. os: also use ubuntu , is same the v5 the v3 code: use std::time::Duration;
use paho_mqtt as mqtt;
use tokio_stream::StreamExt;
use tracing::info;
#[tokio::main]
async fn main(){
tracing_subscriber::fmt::init();
let host = "mqtt://localhost:1883";
let create_opts = mqtt::CreateOptionsBuilder::new_v3()
.server_uri(host)
.client_id("paho-mqtt-client-v3")
.finalize();
let mut cli = mqtt::AsyncClient::new(create_opts).unwrap();
let mut strm = cli.get_stream(25);
let conn_opts = mqtt::ConnectOptionsBuilder::new_v3()
.keep_alive_interval(Duration::from_secs(30))
.clean_session(false)
.finalize();
info!("connecting to mqtt server...");
cli.connect(conn_opts).await.unwrap();
let topic = "mining_updater_topic_test";
info!("subscribing topic: {}", topic);
cli.subscribe(topic, 1).await.unwrap();
info!("waiting for receive message...");
while let Some(msg_opt) = strm.next().await {
if let Some(msg) = msg_opt{
println!("{msg}");
}else{
info!("lost connection to mqtt server");
while let Err(e)= cli.reconnect().await{
println!("Error reconnect: {}",e);
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
}
} |
OK. Thanks. I will try to reproduce it. |
I use paho-mqtt v5 to subscribe to a topic and after a period of almost 12 hours it disconnects
rust version :
the os:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal
this is the Cargo.toml
this is the code :
The text was updated successfully, but these errors were encountered: