Skip to content

Connection Health Status? #649

Answered by Jarema
mbStavola asked this question in Q&A
Sep 29, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

You can use even callback to get the info about state change.

async_nats::ConnectOptions::new().event_callback(|event| async move {
    match event {
    async_nats::Event::Disconnect => println!("disconnected"),
        async_nats::Event::Reconnect => println!("reconnected"),
        async_nats::Event::ClientError(err) => println!("client error occured: {}", err),
        other => println!("other event happened: {}", other),
}
}).connect("demo.nats.io").await?;

To get the current state, you can use
connection state

let client = async_nats::connect("demo.nats.io").await?;
println!("connection state: {}", client.connection_state());

You can also set the ping interval to increase the resolu…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mbStavola
Comment options

Answer selected by mbStavola
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants