Skip to main content

EventLog

Trait EventLog 

Source
pub trait EventLog: Send + Sync {
    // Required methods
    fn append<'life0, 'async_trait>(
        &'life0 self,
        envelope: EventEnvelope,
    ) -> Pin<Box<dyn Future<Output = Result<SeqNo>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn subscribe<'life0, 'life1, 'async_trait>(
        &'life0 self,
        consumer: &'life1 str,
        position: SeekPosition,
    ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = EventEnvelope> + Send>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn ack<'life0, 'life1, 'async_trait>(
        &'life0 self,
        consumer: &'life1 str,
        seq_no: SeqNo,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn seek<'life0, 'life1, 'async_trait>(
        &'life0 self,
        consumer: &'life1 str,
        position: SeekPosition,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn last_seq_no<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<SeqNo>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for persistent event storage backends

Implementations must be Send + Sync to allow sharing across tasks.

§Backends

  • InMemoryEventLog — Vec-backed, suitable for dev/single-instance
  • Future: NATS JetStream, Kafka, Redis Streams

§Consumer Groups

Each consumer has an independent position in the log. The ack method advances the consumer’s position, and seek allows repositioning. Consumer groups enable:

  • Replay: Start from Beginning to reprocess all events
  • Resume: Use LastAcknowledged to pick up where you left off
  • Live: Use Latest to only see new events

Required Methods§

Source

fn append<'life0, 'async_trait>( &'life0 self, envelope: EventEnvelope, ) -> Pin<Box<dyn Future<Output = Result<SeqNo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append an event envelope to the log

Returns the sequence number assigned to the event. Events are assigned monotonically increasing sequence numbers. The envelope’s seq_no field is set by the implementation.

Source

fn subscribe<'life0, 'life1, 'async_trait>( &'life0 self, consumer: &'life1 str, position: SeekPosition, ) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = EventEnvelope> + Send>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Subscribe to events from a given position

Returns a stream of EventEnvelope starting from the specified position. The stream is infinite — it will yield stored events first, then wait for new events as they are appended.

§Arguments
  • consumer - Consumer group name (for tracking position)
  • position - Where to start reading from
Source

fn ack<'life0, 'life1, 'async_trait>( &'life0 self, consumer: &'life1 str, seq_no: SeqNo, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acknowledge that a consumer has processed up to a sequence number

This advances the consumer’s LastAcknowledged position.

Source

fn seek<'life0, 'life1, 'async_trait>( &'life0 self, consumer: &'life1 str, position: SeekPosition, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Seek a consumer to a new position

This changes the consumer’s position without acknowledging. The next subscribe with LastAcknowledged will use this position.

Source

fn last_seq_no<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<SeqNo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the current last sequence number in the log

Returns None if the log is empty.

Implementors§