pub struct StreamConsumer<C = DefaultConsumerContext, R = TokioRuntime>where
C: ConsumerContext,{ /* private fields */ }Expand description
A high-level consumer with a Stream interface.
This consumer doesn’t need to be polled explicitly. Extracting an item from
the stream returned by the stream will
implicitly poll the underlying Kafka consumer.
If you activate the consumer group protocol by calling
subscribe, the stream consumer will integrate with
librdkafka’s liveness detection as described in KIP-62. You must be sure
that you attempt to extract a message from the stream consumer at least
every max.poll.interval.ms milliseconds, or librdkafka will assume that
the processing thread is wedged and leave the consumer groups.
Implementations§
Source§impl<C, R> StreamConsumer<C, R>where
C: ConsumerContext + 'static,
impl<C, R> StreamConsumer<C, R>where
C: ConsumerContext + 'static,
Sourcepub fn stream(&self) -> MessageStream<'_>
pub fn stream(&self) -> MessageStream<'_>
Constructs a stream that yields messages from this consumer.
It is legal to have multiple live message streams for the same consumer, and to move those message streams across threads. Note, however, that the message streams share the same underlying state. A message received by the consumer will be delivered to only one of the live message streams. If you seek the underlying consumer, all message streams created from the consumer will begin to draw messages from the new position of the consumer.
If you want multiple independent views of a Kafka topic, create multiple consumers, not multiple message streams.
Sourcepub fn start(&self) -> MessageStream<'_>
👎Deprecated: use the more clearly named “StreamConsumer::stream” method instead
pub fn start(&self) -> MessageStream<'_>
Constructs a stream that yields messages from this consumer.
Sourcepub async fn recv(&self) -> Result<BorrowedMessage<'_>, KafkaError>
pub async fn recv(&self) -> Result<BorrowedMessage<'_>, KafkaError>
Receives the next message from the stream.
This method will block until the next message is available or an error
occurs. It is legal to call recv from multiple threads simultaneously.
Note that this method is exactly as efficient as constructing a single-use message stream and extracting one message from it:
use futures::stream::StreamExt;
consumer.stream().next().await.expect("MessageStream never returns None");Sourcepub fn split_partition_queue(
self: &Arc<StreamConsumer<C, R>>,
topic: &str,
partition: i32,
) -> Option<StreamPartitionQueue<C, R>>
pub fn split_partition_queue( self: &Arc<StreamConsumer<C, R>>, topic: &str, partition: i32, ) -> Option<StreamPartitionQueue<C, R>>
Splits messages for the specified partition into their own stream.
If the topic or partition is invalid, returns None.
After calling this method, newly-fetched messages for the specified
partition will be returned via StreamPartitionQueue::recv rather
than StreamConsumer::recv. Note that there may be buffered messages
for the specified partition that will continue to be returned by
StreamConsumer::recv. For best results, call split_partition_queue
before the first call to
StreamConsumer::recv.
You must periodically await StreamConsumer::recv, even if no messages
are expected, to serve callbacks. Consider using a background task like:
tokio::spawn(async move {
let message = stream_consumer.recv().await;
panic!("main stream consumer queue unexpectedly received message: {:?}", message);
})Note that calling Consumer::assign will deactivate any existing
partition queues. You will need to call this method for every partition
that should be split after every call to assign.
Beware that this method is implemented for &Arc<Self>, not &self.
You will need to wrap your consumer in an Arc in order to call this
method. This design permits moving the partition queue to another thread
while ensuring the partition queue does not outlive the consumer.
Trait Implementations§
Source§impl<C, R> Consumer<C> for StreamConsumer<C, R>where
C: ConsumerContext,
impl<C, R> Consumer<C> for StreamConsumer<C, R>where
C: ConsumerContext,
Source§fn group_metadata(&self) -> Option<ConsumerGroupMetadata>
fn group_metadata(&self) -> Option<ConsumerGroupMetadata>
Source§fn subscribe(&self, topics: &[&str]) -> Result<(), KafkaError>
fn subscribe(&self, topics: &[&str]) -> Result<(), KafkaError>
Source§fn unsubscribe(&self)
fn unsubscribe(&self)
Source§fn assign(&self, assignment: &TopicPartitionList) -> Result<(), KafkaError>
fn assign(&self, assignment: &TopicPartitionList) -> Result<(), KafkaError>
Source§fn seek<T>(
&self,
topic: &str,
partition: i32,
offset: Offset,
timeout: T,
) -> Result<(), KafkaError>
fn seek<T>( &self, topic: &str, partition: i32, offset: Offset, timeout: T, ) -> Result<(), KafkaError>
offset for the specified topic and partition. After a
successful call to seek, the next poll of the consumer will return the
message with offset.Source§fn commit(
&self,
topic_partition_list: &TopicPartitionList,
mode: CommitMode,
) -> Result<(), KafkaError>
fn commit( &self, topic_partition_list: &TopicPartitionList, mode: CommitMode, ) -> Result<(), KafkaError>
Source§fn commit_consumer_state(&self, mode: CommitMode) -> Result<(), KafkaError>
fn commit_consumer_state(&self, mode: CommitMode) -> Result<(), KafkaError>
Source§fn commit_message(
&self,
message: &BorrowedMessage<'_>,
mode: CommitMode,
) -> Result<(), KafkaError>
fn commit_message( &self, message: &BorrowedMessage<'_>, mode: CommitMode, ) -> Result<(), KafkaError>
Source§fn store_offset(
&self,
topic: &str,
partition: i32,
offset: i64,
) -> Result<(), KafkaError>
fn store_offset( &self, topic: &str, partition: i32, offset: i64, ) -> Result<(), KafkaError>
enable.auto.offset.store should be set to false in the
config.Source§fn store_offset_from_message(
&self,
message: &BorrowedMessage<'_>,
) -> Result<(), KafkaError>
fn store_offset_from_message( &self, message: &BorrowedMessage<'_>, ) -> Result<(), KafkaError>
Consumer::store_offset, but the offset to store is derived from
the provided message.Source§fn store_offsets(&self, tpl: &TopicPartitionList) -> Result<(), KafkaError>
fn store_offsets(&self, tpl: &TopicPartitionList) -> Result<(), KafkaError>
enable.auto.offset.store should be set to false in the config.Source§fn subscription(&self) -> Result<TopicPartitionList, KafkaError>
fn subscription(&self) -> Result<TopicPartitionList, KafkaError>
Source§fn assignment(&self) -> Result<TopicPartitionList, KafkaError>
fn assignment(&self) -> Result<TopicPartitionList, KafkaError>
Source§fn committed<T>(&self, timeout: T) -> Result<TopicPartitionList, KafkaError>
fn committed<T>(&self, timeout: T) -> Result<TopicPartitionList, KafkaError>
Source§fn committed_offsets<T>(
&self,
tpl: TopicPartitionList,
timeout: T,
) -> Result<TopicPartitionList, KafkaError>
fn committed_offsets<T>( &self, tpl: TopicPartitionList, timeout: T, ) -> Result<TopicPartitionList, KafkaError>
Source§fn offsets_for_timestamp<T>(
&self,
timestamp: i64,
timeout: T,
) -> Result<TopicPartitionList, KafkaError>
fn offsets_for_timestamp<T>( &self, timestamp: i64, timeout: T, ) -> Result<TopicPartitionList, KafkaError>
Source§fn offsets_for_times<T>(
&self,
timestamps: TopicPartitionList,
timeout: T,
) -> Result<TopicPartitionList, KafkaError>
fn offsets_for_times<T>( &self, timestamps: TopicPartitionList, timeout: T, ) -> Result<TopicPartitionList, KafkaError>
Source§fn position(&self) -> Result<TopicPartitionList, KafkaError>
fn position(&self) -> Result<TopicPartitionList, KafkaError>
Source§fn fetch_metadata<T>(
&self,
topic: Option<&str>,
timeout: T,
) -> Result<Metadata, KafkaError>
fn fetch_metadata<T>( &self, topic: Option<&str>, timeout: T, ) -> Result<Metadata, KafkaError>
Source§fn fetch_watermarks<T>(
&self,
topic: &str,
partition: i32,
timeout: T,
) -> Result<(i64, i64), KafkaError>
fn fetch_watermarks<T>( &self, topic: &str, partition: i32, timeout: T, ) -> Result<(i64, i64), KafkaError>
Source§fn fetch_group_list<T>(
&self,
group: Option<&str>,
timeout: T,
) -> Result<GroupList, KafkaError>
fn fetch_group_list<T>( &self, group: Option<&str>, timeout: T, ) -> Result<GroupList, KafkaError>
Source§fn pause(&self, partitions: &TopicPartitionList) -> Result<(), KafkaError>
fn pause(&self, partitions: &TopicPartitionList) -> Result<(), KafkaError>
Source§fn resume(&self, partitions: &TopicPartitionList) -> Result<(), KafkaError>
fn resume(&self, partitions: &TopicPartitionList) -> Result<(), KafkaError>
Source§fn rebalance_protocol(&self) -> RebalanceProtocol
fn rebalance_protocol(&self) -> RebalanceProtocol
Source§fn context(&self) -> &Arc<C>
fn context(&self) -> &Arc<C>
ConsumerContext used to create this
consumer.Source§impl<C: ConsumerContext, R> ConsumerExt<C> for StreamConsumer<C, R>
impl<C: ConsumerContext, R> ConsumerExt<C> for StreamConsumer<C, R>
fn process_protobuf_and_commit<'life0, 'life1, 'async_trait, F, T, Fut, E>( &'life0 self, message: Result<BorrowedMessage<'life1>, KafkaError>, process_fn: F, mode: CommitMode, ) -> Pin<Box<dyn Future<Output = Result<(), KakfaProcessError>> + Send + 'async_trait>>
Source§impl<R> FromClientConfig for StreamConsumer<DefaultConsumerContext, R>where
R: AsyncRuntime,
impl<R> FromClientConfig for StreamConsumer<DefaultConsumerContext, R>where
R: AsyncRuntime,
Source§fn from_config(
config: &ClientConfig,
) -> Result<StreamConsumer<DefaultConsumerContext, R>, KafkaError>
fn from_config( config: &ClientConfig, ) -> Result<StreamConsumer<DefaultConsumerContext, R>, KafkaError>
Source§impl<C, R> FromClientConfigAndContext<C> for StreamConsumer<C, R>where
C: ConsumerContext + 'static,
R: AsyncRuntime,
Creates a new StreamConsumer starting from a ClientConfig.
impl<C, R> FromClientConfigAndContext<C> for StreamConsumer<C, R>where
C: ConsumerContext + 'static,
R: AsyncRuntime,
Creates a new StreamConsumer starting from a ClientConfig.
Source§fn from_config_and_context(
config: &ClientConfig,
context: C,
) -> Result<StreamConsumer<C, R>, KafkaError>
fn from_config_and_context( config: &ClientConfig, context: C, ) -> Result<StreamConsumer<C, R>, KafkaError>
Auto Trait Implementations§
impl<C, R> Freeze for StreamConsumer<C, R>
impl<C = DefaultConsumerContext, R = TokioRuntime> !RefUnwindSafe for StreamConsumer<C, R>
impl<C, R> Send for StreamConsumer<C, R>where
R: Send,
impl<C, R> Sync for StreamConsumer<C, R>where
R: Sync,
impl<C, R> Unpin for StreamConsumer<C, R>where
R: Unpin,
impl<C = DefaultConsumerContext, R = TokioRuntime> !UnwindSafe for StreamConsumer<C, R>
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more