Scoped connection

This feature allows to use implicit connection in a block of code. It utilizes ScopedValues package.

Functions

NATS.with_connectionFunction
with_connection(f, nc)

Create scope with ambient context connection, in which connection argument might be skipped during invocation of functions.

Usage:

    nc = NATS.connect()
    with_connection(nc) do
        publish("some.subject") # No `connection` argument.
    end
source

Examples

julia> using NATS
julia> conn1 = NATS.connect()NATS.Connection(unnamed cluster, CONNECTED, 0 subs, 0 unsubs)
julia> conn2 = NATS.connect()NATS.Connection(unnamed cluster, CONNECTED, 0 subs, 0 unsubs)
julia> with_connection(conn1) do sub = subscribe("foo") do msg @show payload(msg) end sleep(0.1) # Wait some time to let server process sub. with_connection(conn2) do publish("foo", "Some payload") end sleep(0.1) # Wait some time to message be delivered. unsubscribe(sub) nothing endpayload(msg) = "Some payload"
julia> conn1.stats.msgs_received == 1true
julia> conn1.stats.msgs_published == 0true
julia> conn2.stats.msgs_received == 0true
julia> conn2.stats.msgs_published == 1true