Skip to main content

Consumer

Trait Consumer 

Source
pub trait Consumer:
    Sized
    + Send
    + Sync {
    type Error: Error;
    type Message<'a>: Message
       where Self: 'a;
    type NextFuture<'a>: Future<Output = Result<Self::Message<'a>, StreamErr<Self::Error>>>
       where Self: 'a;
    type Stream<'a>: Stream<Item = Result<Self::Message<'a>, StreamErr<Self::Error>>>
       where Self: 'a;

    // Required methods
    fn seek(
        &mut self,
        to: OffsetDateTime,
    ) -> impl Future<Output = Result<(), StreamErr<Self::Error>>> + Send;
    fn rewind(
        &mut self,
        offset: SeqPos,
    ) -> impl Future<Output = Result<(), StreamErr<Self::Error>>> + Send;
    fn assign(
        &mut self,
        ss: (StreamKey, ShardId),
    ) -> Result<(), StreamErr<Self::Error>>;
    fn unassign(
        &mut self,
        ss: (StreamKey, ShardId),
    ) -> Result<(), StreamErr<Self::Error>>;
    fn next(&self) -> Self::NextFuture<'_>;
    fn stream<'a, 'b>(&'b mut self) -> Self::Stream<'a>
       where 'b: 'a;
}
Expand description

Common interface of consumers, to be implemented by all backends.

Required Associated Typesยง

Source

type Error: Error

Source

type Message<'a>: Message where Self: 'a

Source

type NextFuture<'a>: Future<Output = Result<Self::Message<'a>, StreamErr<Self::Error>>> where Self: 'a

Source

type Stream<'a>: Stream<Item = Result<Self::Message<'a>, StreamErr<Self::Error>>> where Self: 'a

Required Methodsยง

Source

fn seek( &mut self, to: OffsetDateTime, ) -> impl Future<Output = Result<(), StreamErr<Self::Error>>> + Send

Seek all streams to an arbitrary point in time. It will start consuming from the earliest message with a timestamp later than to.

If the consumer is not already assigned, shard ZERO will be used.

Source

fn rewind( &mut self, offset: SeqPos, ) -> impl Future<Output = Result<(), StreamErr<Self::Error>>> + Send

Rewind all streams to a particular sequence number.

If the consumer is not already assigned, shard ZERO will be used.

Source

fn assign( &mut self, ss: (StreamKey, ShardId), ) -> Result<(), StreamErr<Self::Error>>

Assign this consumer to a particular shard. Can be called multiple times to assign to multiple shards. Returns error StreamKeyNotFound if the stream is not currently subscribed.

It will only take effect on the next Consumer::seek or Consumer::rewind.

Source

fn unassign( &mut self, ss: (StreamKey, ShardId), ) -> Result<(), StreamErr<Self::Error>>

Unassign a shard. Returns error StreamKeyNotFound if the stream is not currently subscribed. Returns error StreamKeyEmpty if all streams have been unassigned.

Source

fn next(&self) -> Self::NextFuture<'_>

Poll and receive one message: it awaits until there are new messages. This method can be called from multiple threads.

Source

fn stream<'a, 'b>(&'b mut self) -> Self::Stream<'a>
where 'b: 'a,

Returns an async stream. You cannot create multiple streams from the same consumer, nor perform any operation while streaming.

Dyn Compatibilityยง

This trait is not dyn compatible.

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

Implementations on Foreign Typesยง

Sourceยง

impl Consumer for KafkaConsumer

Sourceยง

async fn seek( &mut self, timestamp: OffsetDateTime, ) -> Result<(), StreamErr<KafkaError>>

Seek all streams to the given point in time, with all partitions assigned.

ยงWarning

This async method is not cancel safe. You must await this future, and this Consumer will be unusable for any operations until it finishes.

Sourceยง

async fn rewind(&mut self, offset: SeqPos) -> Result<(), StreamErr<KafkaError>>

Rewind all streams across all assigned partitions. Call Consumer::assign to assign a partition beforehand, or KafkaConsumer::reassign_partitions to assign all partitions.

Sourceยง

fn stream<'a, 'b>(&'b mut self) -> <KafkaConsumer as Consumer>::Stream<'a>
where 'b: 'a,

Note: Kafka stream never ends.

Sourceยง

type Error = KafkaError

Sourceยง

type Message<'a> = KafkaMessage<'a>

Sourceยง

type NextFuture<'a> = Map<StreamFuture<MessageStream<'a, DefaultConsumerContext>>, fn((Option<Result<BorrowedMessage<'a>, KafkaError>>, MessageStream<'a, DefaultConsumerContext>)) -> Result<KafkaMessage<'a>, StreamErr<KafkaError>>>

Sourceยง

type Stream<'a> = Map<MessageStream<'a, DefaultConsumerContext>, fn(Result<BorrowedMessage<'a>, KafkaError>) -> Result<KafkaMessage<'a>, StreamErr<KafkaError>>>

Sourceยง

fn assign( &mut self, _: (StreamKey, ShardId), ) -> Result<(), StreamErr<KafkaError>>

Sourceยง

fn unassign( &mut self, s: (StreamKey, ShardId), ) -> Result<(), StreamErr<KafkaError>>

Sourceยง

fn next(&self) -> <KafkaConsumer as Consumer>::NextFuture<'_>

Sourceยง

impl Consumer for StdioConsumer

Sourceยง

fn assign(&mut self, _: (StreamKey, ShardId)) -> Result<(), StreamErr<StdioErr>>

Always succeed if the stream exists. There is only shard ZERO anyway.

Sourceยง

fn unassign( &mut self, _: (StreamKey, ShardId), ) -> Result<(), StreamErr<StdioErr>>

Always fail. There is only shard ZERO anyway.

Sourceยง

type Error = StdioErr

Sourceยง

type Message<'a> = SharedMessage

Sourceยง

type NextFuture<'a> = MapErr<RecvFut<'a, SharedMessage>, fn(RecvError) -> StreamErr<StdioErr>>

Sourceยง

type Stream<'a> = Map<RecvStream<'a, SharedMessage>, fn(SharedMessage) -> Result<SharedMessage, StreamErr<StdioErr>>>

Sourceยง

async fn seek(&mut self, _: OffsetDateTime) -> Result<(), StreamErr<StdioErr>>

Sourceยง

async fn rewind(&mut self, _: SeqPos) -> Result<(), StreamErr<StdioErr>>

Sourceยง

fn next(&self) -> <StdioConsumer as Consumer>::NextFuture<'_>

Sourceยง

fn stream<'a, 'b>(&'b mut self) -> <StdioConsumer as Consumer>::Stream<'a>
where 'b: 'a,

Implementorsยง