Skip to main content

ReceivedEvent

Trait ReceivedEvent 

Source
pub trait ReceivedEvent<E>: Deref<Target = E>
where E: Event,
{ // Required methods fn ack(&self) -> impl Future<Output = Result<(), Error>> + Send; fn context(&self) -> &Context; // Provided method fn event(&self) -> &E { ... } }
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. 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§