Trait MessageLog

Source
pub trait MessageLog<M: RemoteMessage>:
    Sync
    + Send
    + Debug {
    type Stream<'a>: Stream<Item = Result<(SeqId, M), MessageLogError>> + Send
       where Self: 'a;

    // Required methods
    fn append<'life0, 'async_trait>(
        &'life0 mut self,
        message: M,
    ) -> Pin<Box<dyn Future<Output = Result<(), MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn flush<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<SeqId, MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn append_and_flush<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        message: &'life1 M,
    ) -> Pin<Box<dyn Future<Output = Result<SeqId, MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn trim<'life0, 'async_trait>(
        &'life0 mut self,
        new_start: SeqId,
    ) -> Pin<Box<dyn Future<Output = Result<(), MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn read<'life0, 'async_trait>(
        &'life0 self,
        from: SeqId,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'_>, MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn read_one<'life0, 'async_trait>(
        &'life0 self,
        seq_id: SeqId,
    ) -> Pin<Box<dyn Future<Output = Result<M, MessageLogError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

This MessageLog is a log that serves as a building block to persist data before the consumer can process it. One typical example is to persist messages before an actor handles it. In such a case, it can be used as a white-ahead log. It allows the actor to recover from a crash without requesting resending the messages. The log is append-only and the messages are persisted in order with sequence ids.

Required Associated Types§

Source

type Stream<'a>: Stream<Item = Result<(SeqId, M), MessageLogError>> + Send where Self: 'a

The type of the stream returned from read operations on this log.

Required Methods§

Source

fn append<'life0, 'async_trait>( &'life0 mut self, message: M, ) -> Pin<Box<dyn Future<Output = Result<(), MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append a message to a buffer. The appended messages will only be persisted and available to read after calling [flush].

Source

fn flush<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<SeqId, MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flush the appended messages. Return the next sequence id of the last persistent message.

Source

fn append_and_flush<'life0, 'life1, 'async_trait>( &'life0 mut self, message: &'life1 M, ) -> Pin<Box<dyn Future<Output = Result<SeqId, MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Directly flush the message. All previously buffered messages will be flushed as well. This convenience method can prevent an additional copy of the message by directly writing to the log.

Source

fn trim<'life0, 'async_trait>( &'life0 mut self, new_start: SeqId, ) -> Pin<Box<dyn Future<Output = Result<(), MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Trim the persistent logs before the given [new_start] non-inclusively.

Source

fn read<'life0, 'async_trait>( &'life0 self, from: SeqId, ) -> Pin<Box<dyn Future<Output = Result<Self::Stream<'_>, MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Given a sequence id, return a stream of message and sequence id tuples that are persisted after the given sequence id inclusively. The stream will yield errors when streaming messages back if any. It will also yield errors if creating the stream itself fails.

Source

fn read_one<'life0, 'async_trait>( &'life0 self, seq_id: SeqId, ) -> Pin<Box<dyn Future<Output = Result<M, MessageLogError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read exactly one message from the log. If the log is empty, return an error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§