下面显示的是英文原文。
Channels
A publish channel reports its socket pair and, on PUSH/PULL and PUB/SUB, nameFrame: the frame 0 a peer sends or subscribes with.
Each destination a mount site publishes to is a channel of the document.
Its x-ruststream-zeromq extension comes from the publish policy, so it says how messages leave this service.
socketPair is PUSH/PULL, PUB/SUB or DEALER/ROUTER.
nameFrame is the value frame 0 holds on the wire, which is the destination itself.
A peer reads from it what to send to reach the channel and, on PUB/SUB, which prefix to subscribe with.
A responder's reply channel reports no nameFrame.
An answer travels to the identity the ROUTER supplies, and its frame 0 always holds reply, so the channel's own name reaches no peer.
Peers in other languages shows which frame 0 a peer sends or subscribes with.
Example
The worker's results go to results over PUSH/PULL, so the channel reports nameFrame: results.
- Macros
- Manual
// No destination of its own: the clause names `results`, the name frame of every result.
#[derive(Debug, Serialize, Outgoing)]
struct Done {
id: u64,
}
#[subscriber("jobs", reply("results"))]
async fn work(job: &Job) -> Done {
tracing::info!(job.id, "working");
Done { id: job.id }
}
#[derive(Debug, Serialize, JsonSchema)]
#[schemars(crate = "ruststream::schemars")]
struct Done {
id: u64,
}
// No destination of its own: the mount names `results`, the name frame of every result.
impl OutgoingDestination for Done {
type Form = CallerName;
}
impl MessageHeaders for Done {
type Contract = NoHeaders;
}
struct Work;
impl Handle<Job, Done> for Work {
fn handle(
&self,
job: &Job,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<Done, HandlerOutcome>> {
tracing::info!(job.id, "working");
ready(Ok(Done { id: job.id }))
}
}