blob: 4eab93046d82cb7e4b1f5dde3a7b3a6adc405a4c [file] [log] [blame]
---
layout: default
---
:source-highlighter: coderay
:icons: font
include::_banner.adoc[]
== Request/Reply (I ask, you answer)
image::reqrep.png[I ask, you answer]
Request/Reply is used for synchronous communications where each question
is responded with a single answer, for example remote procedure calls (RPCs).
Like <<pipeline#,Pipeline>>, it also can perform load-balancing. This
is the only reliaable messaging pattern in the suite, as it automatically
will retry if a request is not matched with a response.
.reqprep.c
[source,c]
----
include::src/reqrep.c[]
----
<1> Blithely assumes message is ASCIIZ string. Real code should check it.
.Compilation
[source,bash]
----
gcc reqrep.c -lnanomsg -o reqrep
----
.Execution
[source,bash]
----
./reqrep node0 ipc:///tmp/reqrep.ipc & node0=$! && sleep 1
./reqrep node1 ipc:///tmp/reqrep.ipc
kill $node0
----
.Output
----
NODE1: SENDING DATE REQUEST DATE
NODE0: RECEIVED DATE REQUEST
NODE0: SENDING DATE Sat Sep 7 17:39:01 2013
NODE1: RECEIVED DATE Sat Sep 7 17:39:01 2013
----