Debugging
Monitoring connection state
julia> using NATSjulia> nc = NATS.connect()NATS.Connection(unnamed cluster, CONNECTED, 0 subs, 0 unsubs)julia> @async NATS.status_change(nc) do state @info "Connection to $(NATS.clustername(nc)) changed state to $state" endTask (runnable) @0x00007f352d87e8b0julia> NATS.reconnect(nc)┌ Warning: Connection to unnamed cluster on `nats://localhost:4222` lost, trynig to reconnect. └ @ NATS ~/work/NATS.jl/NATS.jl/src/connection/connect.jl:387 [ Info: Connection to unnamed changed state to CONNECTINGjulia> NATS.drain(nc)[ Info: Reconnected to unnamed cluster on `nats://localhost:4222` after 0.01729297637939453 seconds. [ Info: Connection to unnamed changed state to CONNECTED [ Info: Connection to unnamed changed state to DRAININGjulia> sleep(7) # Wait a moment to get DRAINED status as well
Connection and subscription statistics
There are detailed statistics of published and received messages collected. They can be accessed for each subscription and connection. Connection statistics aggregates stats for all its subscriptions.
julia> using NATSjulia> nc = NATS.connect()NATS.Connection(unnamed cluster, CONNECTED, 0 subs, 0 unsubs)julia> sub1 = subscribe(nc, "topic") do msg t = Threads.@spawn publish(nc, "other_topic", payload(msg)) wait(t) endNATS.Sub("topic", nothing, 1)julia> sub2 = subscribe(nc, "other_topic") do msg @show payload(msg) endNATS.Sub("other_topic", nothing, 2)julia> NATS.stats(nc)published: 0 received: 0 pending: 0 active: 0 handled: 0 errored: 0 dropped: 0julia> publish(nc, "topic", "Hi!")julia> NATS.stats(nc)published: 1 received: 1 pending: 1 active: 0 handled: 0 errored: 0 dropped: 0julia> NATS.stats(nc, sub1)published: 1 received: 1 pending: 0 active: 0 handled: 1 errored: 0 dropped: 0julia> NATS.stats(nc, sub2)published: 0 received: 1 pending: 1 active: 0 handled: 0 errored: 0 dropped: 0julia> sleep(0.1) # Wait for message to be propagatedpayload(msg) = "Hi!"julia> NATS.stats(nc)published: 2 received: 2 pending: 0 active: 0 handled: 2 errored: 0 dropped: 0julia> NATS.stats(nc, sub1)published: 1 received: 1 pending: 0 active: 0 handled: 1 errored: 0 dropped: 0julia> NATS.stats(nc, sub2)published: 0 received: 1 pending: 0 active: 0 handled: 1 errored: 0 dropped: 0julia> NATS.drain(nc)