Request - Reply
Functions implementing Request-Reply pattern.
NATS.request
— Functionrequest(connection, subject; ...)
request(connection, subject, data; timer)
Send NATS Request-Reply message.
Default timeout is 5.0 seconds which can be overriden by passing timer
. It can be configured globally with NATS_REQUEST_TIMEOUT_SECONDS
env variable.
Optional keyword arguments are:
timer
: error will be thrown if no replies received untiltimer
expires
Examples
julia> NATS.request(connection, "help.please")
NATS.Msg("l9dKWs86", "7Nsv5SZs", nothing, "", "OK, I CAN HELP!!!")
julia> request(connection, "help.please"; timer = Timer(0))
ERROR: No replies received.
request(connection, nreplies, subject; ...)
request(connection, nreplies, subject, data; timer)
Requests for multiple replies. Vector of messages is returned after receiving nreplies
replies or timer expired. Can return less messages than specified (also empty array if timeout occurs), errors are not filtered.
Optional keyword arguments are:
timer
: empty vector will be returned if no replies received untiltimer
expires
Examples
julia> request(connection, 2, "help.please"; timer = Timer(0))
NATS.Msg[]
Request a reply from a service listening for subject
messages. Reply is converted to specified type. Apropriate convert
method must be defined, otherwise error is thrown.
NATS.reply
— Functionreply(f, connection, subject; queue_group, spawn)
Reply for messages for a subject
. Works like subscribe
with automatic publish
to the subject from reply_to
field.
Optional keyword arguments are:
queue_group
: NATS server will distribute messages across queue group membersspawn
: iftrue
task will be spawn for eachf
invocation, otherwise messages are processed sequentially, default isfalse
Examples
julia> sub = reply("FOO.REQUESTS") do msg
"This is a reply payload."
end
NATS.Sub("FOO.REQUESTS", nothing, "jdnMEcJN")
julia> sub = reply("FOO.REQUESTS") do msg
"This is a reply payload.", ["example_header" => "This is a header value"]
end
NATS.Sub("FOO.REQUESTS", nothing, "jdnMEcJN")
julia> unsubscribe(sub)