bytebeamio / rumqtt

The MQTT ecosystem in rust
Apache License 2.0
1.64k stars 252 forks source link

Adds on_disconnect handler to rumqttd. #776

Closed nathansizemore closed 10 months ago

nathansizemore commented 11 months ago

We're using rumqttd against devices that uses v4 protocol and do not always disconnect gracefully. It appears in this circumstance, the broker never reports a disconnect notification as would be expected here:

link_tx.subscribe("#").unwrap();

loop {
    let notification = match link_rx.recv().unwrap() {
        Some(v) => v,
        None => continue,
    };

    match notification {
        Notification::Forward(forward) => println!("forward"),
        Notification::Disconnect(d, props) => println!("disconnect: \n{d:#?}\n{props:#?}"),
        v => println!("{v:?}"),
    }
}

We also start processes based on a client id, so not having access to that information when the client is no longer connected is a pain point this also solves by passing in the id for the disconnected client to the handler.

This is related to #775 .

Type of change

New feature (non-breaking change which adds functionality)

Checklist:

nathansizemore commented 10 months ago

closing in favor of another PR will impl a little differently.