Skip to main content

ReceivedEvent

Trait ReceivedEvent 

Source
pub trait ReceivedEvent<E: Event>: Deref<Target = E> {
    // Required methods
    fn ack(&self) -> impl Future<Output = Result<(), Error>> + Send;
    fn context(&self) -> &Context;

    // Provided method
    fn event(&self) -> &E { ... }
}
Expand description

An event received from the message bus that can be acknowledged.

Implements Deref to give direct access to the inner event data.

Required Methods§

Source

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

Acknowledge processing of this event.

Tells the message broker that the event was processed successfully and should not be redelivered. If acknowledgment fails, the event may be reprocessed by this or another service instance.

§Errors

Returns Error::AckFailed if the acknowledgment could not be sent.

Source

fn context(&self) -> &Context

Returns the OpenTelemetry context propagated with this event.

Use this to continue a distributed trace across the service boundary:

let ctx = event.context().clone();
async move {
	println!("{:?}", event.event());
	event.ack().await
}
.with_context(ctx)
.await

Provided Methods§

Source

fn event(&self) -> &E

Returns a reference to the received event data.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§