-
As part of my service's health check I'd like to be able to inspect the health status of the NATS connection. I see that I'm using async-nats, by the way. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 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 resolution at which connection state is checked when there is not a lot of activity / other signs of disconnect. async_nats::ConnectOptions::new().flush_interval(Duration::from_secs(5)).connect("demo.nats.io").await?; |
Beta Was this translation helpful? Give feedback.
You can use even callback to get the info about state change.
To get the current state, you can use
connection state
You can also set the ping interval to increase the resolu…