Эта страница ещё не переведена
Ниже показан английский оригинал.
Errors
ZmqError is the one error type of the crate: endpoint, send, receive, wire, request timeout, not connected, invalid.
Each variant names the step that failed.
The ZeroMQ client's own error is the source of Endpoint, so the client's types stay out of the crate's API.
| Variant | When |
|---|---|
Endpoint | a socket could not bind or dial its address, such as a port another process holds at startup, or a peer that did not listen within 30 seconds |
Send | a message could not leave: a publish its own subscription would receive back, a publish to a peer that only sends, an answer to a requester that has gone, a header the text frame cannot carry, or no peer within five seconds |
Receive | an open subscription failed to receive |
Wire | a peer sent frames that do not follow the wire layout |
RequestTimeout | a request got no answer within its timeout |
NotConnected | a publisher, a responder or a request was used after the broker shut down |
Invalid | an address with a scheme other than tcp:// or ipc://, or a second subscription on an endpoint the broker binds |
A service meets the error in two places.
A failed startup carries it as the source of the runtime's error, and the service exits before it reads anything.
A publish from a handler returns it inside the core's PublishError, and the handler decides how the delivery settles.
The enum is #[non_exhaustive], so a match on it ends with a wildcard arm.
Example
A result the socket refuses is logged with its cause, and the job is settled as a retry in a second.
- Macros
- Manual
#[subscriber("jobs")]
async fn work(job: &Job, Out(results): Out<impl Publisher, Results>) -> HandlerOutcome {
if let Err(err) = results.message(&Done { id: job.id }).publish().await {
// The error names the destination and the socket's reason.
tracing::warn!(subscription = "jobs", job.id, error = %err, "result not published");
return HandlerOutcome::retry_after(Duration::from_secs(1));
}
HandlerOutcome::ack()
}
struct Work;
impl<Entry> Handle<Job, (), Outs<(Entry,)>> for Work
where
Entry: OutEntry<Results, Wire: Publisher>,
{
async fn handle(
&self,
job: &Job,
outs: &Outs<(Entry,)>,
_ctx: &mut Context<'_>,
) -> Result<(), HandlerOutcome> {
let done = Done { id: job.id };
if let Err(err) = outs.get(Results).message(&done).publish().await {
// The error names the destination and the socket's reason.
tracing::warn!(subscription = "jobs", job.id, error = %err, "result not published");
return Err(HandlerOutcome::retry_after(Duration::from_secs(1)));
}
Ok(())
}
}