Перейти к основному содержимому
Эта страница ещё не переведена

Ниже показан английский оригинал.

Envelope

On DEALER/ROUTER a request carries correlation-id, and its answer travels behind the requester's identity with frame 0 holding reply.

A requester sends the usual three frames from a DEALER socket, with a correlation-id line in the header frame. The responder's ROUTER puts the DEALER's identity in front of them; ZeroMQ calls that frame the envelope. The responder reads the identity off and gives the request a reply-to header that addresses it.

The answer goes back through the ROUTER as [identity, "reply", headers, payload]. The ROUTER takes the identity frame off to route it, so the DEALER reads three frames: the literal reply, the header lines with the request's correlation-id, and the payload. The requester matches the answer to its request by that id, because frame 0 is the same on every answer. The correlation-id reaches the answer through the responder's transform.

Peers in other languages asks a responder from a Python DEALER.

Example​

A Python requester:

dealer.send_multipart([b"greeter", b"correlation-id: ask-1", b'{"who": "world"}'])
name, headers, payload = dealer.recv_multipart()

The greeter binds tcp://0.0.0.0:5557 and answers each DEALER that asks.

fn service(endpoint: ZmqEndpoint) -> impl App {
RustStream::new(AppInfo::new("greeter", "0.1.0")).with_broker(ZmqRpc::new(endpoint), |b| {
// The answer goes to the identity the ROUTER read off the request, and it carries the
// request's `correlation-id` back.
b.include(greet)
.out_reply(Publish)
.transform(ReplyToRequester)
.out_retry(Publish)
.to("greeter.retry");
})
}

#[ruststream::app]
fn app() -> impl App {
service(ZmqEndpoint::bind("tcp://0.0.0.0:5557"))
}