The Simple Reply Envelope
A request-reply exchange consists of a request message, and an eventual reply message. In the simple request-reply pattern thereâs one reply for each request. In more advanced patterns, requests and replies can flow asynchronously. However, the reply envelope always works the same way.
The ÃMQ reply envelope formally consists of zero or more reply addresses, followed by an empty frame (the envelope delimiter), followed by the message body (zero or more frames). The envelope is created by multiple sockets working together in a chain. Weâll break this down.
Weâll start by sending âHelloâ through a REQ socket. The REQ socket creates the simplest possible reply envelope, which has no addresses, just an empty delimiter frame and the message frame containing the âHelloâ string. This is a two-frame message (Figure 3-1).
Figure 3-1. Request with minimal envelope
The REP socket does the matching work: it strips off the envelope, up to and including the delimiter frame, saves the whole envelope, and passes the âHelloâ string up the application. Thus, our original âHello Worldâ example used request-reply envelopes internally, but the application never saw them.
If you spy on the network data flowing between hwclient and hwserver, this is what youâll see: every request and every reply is in fact two frames, an empty frame and then the body. This ...
Get ZeroMQ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.