bytebeamio / rumqtt

The MQTT ecosystem in rust
Apache License 2.0
1.58k stars 246 forks source link

rumqttc "Stream done" after 70 minutes, no messages on reconnect? #107

Closed krystianity closed 4 years ago

krystianity commented 4 years ago

Hi there.

I am trying to run the following code (actually taken from the syncpubsub example), just wrapped in a loop (in an attempt reconnect).

I am using rumqttc "0.0.4" and used "cross" to compile on MacOS (via Rust 1.43.1) for ARM, testing on a Rasperry Pi 4. The code runs fine for a while, consuming and processing MQTT messages, however after about 70 minutes the invoke value resolves in an Error("Stream done"). I tried to wrap the connection.iter in a loop hoping it would reconnect, which seems like it worked. However it does not receive messages from the subscribed topic anymore.

Any idea what I am doing wrong? btw. you can find the whole code here

Snippet:


let (mut client, mut connection) = Client::new(mqtt_options, 10);

 client.subscribe(event_topic.as_str(), QoS::AtMostOnce)
            .expect("Failed to subscribe to mqtt event topic");

        loop {

            for (_i, invoke) in connection.iter().enumerate() {

                  match invoke {
                    Err(e) => {
                        error!("mqtt error {}", e);
                        continue;
                    },
                    _ => ()
                };

                let (inc, _out) = invoke.unwrap();
                if inc.is_none() {
                    continue;
                }

                match inc.unwrap() {
                    Incoming::Publish(message) => {

                        let payload = str::from_utf8(&message.payload);
                        if payload.is_err() {
                            error!("Failed to decode mqtt payload {:?}", payload);
                            continue;
                        }
                        let payload = payload.unwrap();

                      /* some business logic here.. */
                    },
                    _ => continue
                }
            }

        }

thx

tekjar commented 4 years ago

@krystianity Sorry I missed this issue. Stream done means that server has closed your connection. You need to set clean session to false for broker to not forget subscription.

tekjar commented 4 years ago

Also iLert looks good. Don't hesitate to ping me in discord if you would like more support.

krystianity commented 4 years ago

@tekjar thanks Ravi, I missed that in the docs. 🥰