Эта страница ещё не переведена
Ниже показан английский оригинал.
Message
Message<H, T> hands a handler the decoded payload and its parsed header contract as one input.
chunk.headers is the contract and chunk.body the payload.
The contract parses the way Headers<T> parses it, and a contract that does not parse is a decode failure.
A batch handler takes &[Message<H, T>], so each element keeps its own headers.
A reply typed Message<H, T> carries its headers the same way.
Example
- Macros
- Manual
/// The payload and its contract arrive decoded together.
#[subscriber("chunks")]
async fn store(chunk: &Message<ChunkMeta, Chunk>) -> HandlerOutcome {
let meta = &chunk.headers;
if meta.chunk_no >= meta.chunks_total {
// A chunk past the end of its task.
return HandlerOutcome::drop();
}
tracing::info!(meta.task_id, meta.chunk_no, chunk.body.size, "stored");
HandlerOutcome::ack()
}
/// The payload and its contract arrive decoded together.
struct Store;
impl Handle<Message<ChunkMeta, Chunk>> for Store {
fn handle(
&self,
chunk: &Message<ChunkMeta, Chunk>,
_outs: &(),
_ctx: &mut Context<'_>,
) -> impl Future<Output = Result<(), HandlerOutcome>> {
let meta = &chunk.headers;
if meta.chunk_no >= meta.chunks_total {
// A chunk past the end of its task.
return ready(Err(HandlerOutcome::drop()));
}
tracing::info!(meta.task_id, meta.chunk_no, chunk.body.size, "stored");
ready(Ok(()))
}
}