Skip to main content

OutMessages

Trait OutMessages 

Source
pub trait OutMessages<M>
where M: OutSlot,
{ // Required method fn outgoing() -> Vec<OutgoingMessageMetadata>; }
Expand description

A declared message set’s AsyncAPI contribution: one OutgoingMessageMetadata entry per member, each read off the member’s own declaration.

Implemented by #[derive(Outgoing)] (the type declares itself and where it goes) and by #[derive(OutMessages)] on a set enum (each variant’s model); () falls back to the whole dictionary. A tuple declaration needs no impl - the #[subscriber] macro enumerates its elements itself.

§Examples

use ruststream::memory::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct Order {
    id: u64,
}

#[derive(Serialize, Outgoing)]
#[outgoing(name = "chunks.progress")]
struct Progress {
    percent: u8,
}

#[derive(Serialize, Outgoing)]
#[outgoing(name = "chunks.done")]
struct ChunkDone {
    output_key: String,
}

/// A reusable named set: the variants' models are what a handler naming `ConvertSends` as
/// its third `Out` argument publishes. The enum is never constructed.
#[derive(OutMessages)]
enum ConvertSends {
    Progress(Progress),
    Done(ChunkDone),
}

#[derive(OutSlot)]
#[publishes(Progress, ChunkDone)]
struct Events;

#[subscriber("orders")]
async fn convert(
    order: &Order,
    Out(events): Out<impl Publisher, Events, ConvertSends>,
) -> HandlerOutcome {
    let done = ChunkDone {
        output_key: format!("out/{}", order.id),
    };
    if events
        .message(&Progress { percent: 100 })
        .publish()
        .await
        .is_err()
        || events.message(&done).publish().await.is_err()
    {
        return HandlerOutcome::retry();
    }
    HandlerOutcome::ack()
}

fn app() -> RustStream {
    RustStream::new(AppInfo::new("convert", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(convert).out(Events, Publish).build();
    })
}

Required Methods§

Source

fn outgoing() -> Vec<OutgoingMessageMetadata>

The set’s declared outgoing messages, for the generated document. Called once at registration; never on the publish path.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<M> OutMessages<M> for ()
where M: OutSlot,

Implementors§