Request - Reply
Functions implementing the Request-Reply pattern.
NATS.request — Functionrequest(connection, subject; ...)
request(connection, subject, data; timeout)
Send a NATS Request-Reply message.
The default timeout is 5.0 seconds which can be overridden by passing timeout. It can be configured globally with the NATS_REQUEST_TIMEOUT_SECONDS env variable.
Optional keyword arguments are:
timeout: error will be thrown if no replies are received untiltimeoutnumber of seconds,NATS.SendDeadlineExceededif the request could not be queued for sending in that time
Examples
julia> NATS.request(connection, "help.please")
MSG _INBOX.VnRLq6t91z.1 0 17
OK, I CAN HELP!!!
julia> request(connection, "help.please"; timeout = 0)
ERROR: Send deadline exceeded.request(connection, nreplies, subject; ...)
request(
connection,
nreplies,
subject,
data;
timeout,
stop_on_status
)
Requests for multiple replies. Vector of messages is returned after receiving nreplies replies, a reply with one of stop_on_status codes or the timer expired. Can return less messages than specified (also an empty array if a timeout occurs), errors are not filtered.
Optional keyword arguments are:
timeout: an empty vector will be returned if no replies are received untiltimeoutnumber of secondsstop_on_status: a collection of status codes, a reply with one of them is the last collected and the remaining replies are not waited for. By default it is every error status (400:599), what includes503sent by the server when there are no responders. Replies with other statuses are collected as any other reply, pass an empty collection to always wait fornrepliesreplies or thetimeout.
Examples
julia> request(connection, 2, "help.please"; timeout = 0)
ERROR: Send deadline exceeded.Request a reply from a service listening for subject messages. Reply is converted to specified type. An appropriate convert method must be defined, otherwise an 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: iftruea task will be spawned 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)