Skip to main content

subscriber

Attribute Macro subscriber 

Source
#[subscriber]
Expand description

Turns an async fn handler into a mountable subscriber definition.

/// Processes incoming orders.
#[subscriber("orders")]
async fn handle(order: &Order) -> HandlerResult { HandlerResult::Ack }
// later: broker_scope.include(handle, JsonCodec);

// reply form: the return value is encoded and published to "responses" through the
// TypedPublisher (broker + reply codec) passed at wiring time.
#[subscriber("requests", publish("responses"))]
async fn reply(req: &Request) -> Response { /* ... */ }
// later: broker_scope.include_publishing(reply, JsonCodec, typed_publisher);

Without publish(..) the handler returns any IntoHandlerResult (a HandlerResult, (), or Result<_, E>). With publish(..) it returns the reply value to publish.