Request - Reply
Functions implementing Request-Reply pattern.
NATS.request — Functionrequest(connection, subject; ...)
request(connection, subject, data; timeout)
Send NATS Request-Reply message.
Default timeout is 5.0 seconds which can be overriden by passing timeout. It can be configured globally with NATS_REQUEST_TIMEOUT_SECONDS env variable.
Optional keyword arguments are:
timeout: error will be thrown if no replies received untiltimeoutnumber of seconds
Examples
julia> NATS.request(connection, "help.please")
NATS.Msg("l9dKWs86", "7Nsv5SZs", nothing, "", "OK, I CAN HELP!!!")
julia> request(connection, "help.please"; timeout = 0)
ERROR: No replies received.request(connection, nreplies, subject; ...)
request(connection, nreplies, subject, data; timeout)
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:
timout: empty vector will be returned if no replies received untiltimeoutnumber of seconds
Examples
julia> request(connection, 2, "help.please"; timeout = 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: iftruetask will be spawn for eachfinvocation, 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)