How to use point-to-point request reply?

265 views
Skip to first unread message

Žygimantas Stauga

unread,
Jun 7, 2016, 6:53:57 AM6/7/16
to nats
http://nats.io/documentation/concepts/nats-req-rep/
"NATS supports two flavors of request reply messaging: point-to-point or one-to-many"

But I can't find anything on documentation about point-to-point messaging. Checked request reply examples - all subscribers are receiving same message. It's ok when you trying to replace GET http requests, but it's not ok with POST like requests... Am I missing something?

Ivan Kozlovic

unread,
Jun 7, 2016, 10:02:58 AM6/7/16
to nats
When calling Request() (check specifics for your language of choice), the API automatically unsubscribes after receiving 1 response. This means that you can have many subscribers, but the requestor cares (and returns) only the first reply. The client library ensures that only one message is given back to the caller, but also the server drops interest on the reply INBOX (created in the Request call). The "repliers" (applications sending back a reply) may still send their reply, but the server will ignore them.

If you want to have only one of the subscribers receive a given request, you should have all subscribers part of a queue group (QueueSubscribe() in Go for instance). They all subscribe to the same subject, but only one will receive the request. The server picks one randomly. 

Hope this helps.

Larry McQueary

unread,
Jun 7, 2016, 10:25:15 AM6/7/16
to nat...@googlegroups.com
For point to point request-reply, all members of the "replier" pool must be subscribed as per of a queue group. This ensures that only one member gets the request.
--
You received this message because you are subscribed to the Google Groups "nats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to natsio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Larry McQueary | Director, Messaging Technology

Žygimantas Stauga

unread,
Jun 7, 2016, 11:59:40 PM6/7/16
to nats
Ok, thanks. Just wanted to check is there implemented logic in a go clien. Looks like I have to implement Request() logic https://github.com/nats-io/nats/blob/master/nats.go#L1705 myself with QueueSubscribe().

Žygimantas Stauga

unread,
Jun 8, 2016, 12:57:41 AM6/8/16
to nats
Oh, nevermind. Request part leaves unchanged, only part what I needed to change - subscription type. Thanks again!

Larry McQueary

unread,
Jun 8, 2016, 12:58:21 AM6/8/16
to nat...@googlegroups.com
:)


On Tuesday, June 7, 2016, Žygimantas Stauga <z.st...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "nats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to natsio+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages