pub struct KafkaConsumer {
inner: StreamConsumer<TracingContext>,
}
Expand description
Fields§
§inner: StreamConsumer<TracingContext>
Implementations§
Source§impl KafkaConsumer
impl KafkaConsumer
Sourcepub fn get_default_config(
bootstrap_servers: &str,
group_id: &str,
credentials: &ClientCredentials,
) -> ClientConfig
pub fn get_default_config( bootstrap_servers: &str, group_id: &str, credentials: &ClientCredentials, ) -> ClientConfig
Sourcepub fn new(topics: &[Topic], config: ClientConfig) -> Result<Self>
pub fn new(topics: &[Topic], config: ClientConfig) -> Result<Self>
Explicit configuration.
§Arguments
topics
- The topics to subscribe toconfig
- The consumer configuration
§Returns
Result<Self, SDKError>
- The result of the operation
§Errors
SDKError::Consumer
- If the consumer fails to create.
Sourcepub fn default(
bootstrap_servers: &str,
topics: &[Topic],
group_id: &str,
credentials: &ClientCredentials,
) -> Result<Self>
pub fn default( bootstrap_servers: &str, topics: &[Topic], group_id: &str, credentials: &ClientCredentials, ) -> Result<Self>
Default configuration.
§Arguments
topics
- The topics to subscribe togroup_id
- The group id to use for the consumercredentials
- The credentials to use for authentication
§Returns
Result<Self, SDKError>
- The result of the operation
§Errors
SDKError::Consumer
- If the consumer fails to create.
Sourcepub fn default_with_strings(
bootstrap_servers: &str,
topics: &[&str],
group_id: &str,
credentials: &ClientCredentials,
) -> Result<Self>
pub fn default_with_strings( bootstrap_servers: &str, topics: &[&str], group_id: &str, credentials: &ClientCredentials, ) -> Result<Self>
Default configuration with string topics.
§Arguments
topics
- The topics to subscribe togroup_id
- The group id to use for the consumerbootstrap_servers
- The bootstrap servers to use for the consumercredentials
- The credentials to use for authentication
§Returns
Result<Self, SDKError>
- The result of the operation
§Errors
SDKError::Consumer
- If the consumer fails to create.
Sourcepub fn stream(
&self,
) -> impl Stream<Item = KafkaResult<BorrowedMessage<'_>>> + '_
pub fn stream( &self, ) -> impl Stream<Item = KafkaResult<BorrowedMessage<'_>>> + '_
Async stream of messages (KafkaResult<BorrowedMessage>
).
§Returns
impl Stream<Item = KafkaResult<BorrowedMessage<'_>>> + '_
- The stream of messages
Sourcepub fn event_stream(
&self,
) -> impl Stream<Item = Result<EventStream, SDKError>> + '_
pub fn event_stream( &self, ) -> impl Stream<Item = Result<EventStream, SDKError>> + '_
Async stream of deserialized EventStream messages.
This method provides a higher-level API that automatically deserializes
Kafka messages into EventStream
objects. This eliminates the need for
manual deserialization in your application code.
§Returns
impl Stream<Item = Result<EventStream, SDKError>> + '_
- The stream of deserialized events
§Errors
SDKError::Consumer
- If the consumer fails to deserialize the message.
Sourcepub fn inner(&self) -> &StreamConsumer<TracingContext>
pub fn inner(&self) -> &StreamConsumer<TracingContext>
Get the underlying consumer for manual polling.
§Returns
&StreamConsumer<TracingContext>
- The underlying consumer
Sourcepub fn commit_message(&self, msg: &BorrowedMessage<'_>, mode: CommitMode)
pub fn commit_message(&self, msg: &BorrowedMessage<'_>, mode: CommitMode)
Sourcepub fn deserialize_message(
&self,
msg: &BorrowedMessage<'_>,
) -> Result<EventStream>
pub fn deserialize_message( &self, msg: &BorrowedMessage<'_>, ) -> Result<EventStream>
Deserializes a Kafka message into an EventStream<T>
.
T
must implementserde::Serialize
andserde::de::DeserializeOwned
.
§Arguments
msg
- The message to deserialize
§Returns
Result<EventStream, SDKError>
- The result of the operation
§Errors
SDKError::Consumer
- If the consumer fails to deserialize the message.
Auto Trait Implementations§
impl Freeze for KafkaConsumer
impl !RefUnwindSafe for KafkaConsumer
impl Send for KafkaConsumer
impl Sync for KafkaConsumer
impl Unpin for KafkaConsumer
impl !UnwindSafe for KafkaConsumer
Blanket Implementations§
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
Mutably borrows from an owned value. Read more