Skip to main content

ReceivedCommand

Trait ReceivedCommand 

Source
pub trait ReceivedCommand<C>: Deref<Target = C>
where C: Command,
{ // Required methods fn ack(&self) -> impl Future<Output = Result<(), Error>> + Send; fn reply( &self, response: <C as Command>::Reply, ) -> impl Future<Output = Result<(), Error>> + Send; fn context(&self) -> &Context; // Provided method fn command(&self) -> &C { ... } }
Expand description

Re-exported so services only need to depend on arminius-lib-nats.

The message-bus Subscriber trait is intentionally not re-exported here to avoid clashing with the async_nats::Subscriber re-export above; reach it via arminius_lib_message_bus::Subscriber. A received command that must be acknowledged with a typed reply.

Required Methods§

Source

fn ack(&self) -> impl Future<Output = Result<(), Error>> + Send

Take responsibility for the command without answering it yet.

A handler that acknowledges up front trades the certainty of eventually receiving an answer for the certainty that nothing can hand the command out a second time: a crash or a stall past this point costs the reply rather than repeating whatever the handler had already done. This is what a Delivery::AtMostOnce command asks for:

ⓘ
received.ack().await?;
let reply = claim_keys(received.command()).await;
received.reply(reply).await?;

reply acknowledges as well, so a handler that is happy to be run again should never call this.

Source

fn reply( &self, response: <C as Command>::Reply, ) -> impl Future<Output = Result<(), Error>> + Send

Send response back to the requester and acknowledge the command.

Source

fn context(&self) -> &Context

Returns the OpenTelemetry context propagated with this command.

Provided Methods§

Source

fn command(&self) -> &C

Returns a reference to the received command data.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§