pub struct Consumer { /* private fields */ }
Expand description
The Kafka Consumer
See module level documentation.
Implementations§
source§impl Consumer
impl Consumer
sourcepub fn from_client(client: KafkaClient) -> Builder
pub fn from_client(client: KafkaClient) -> Builder
Starts building a consumer using the given kafka client.
sourcepub fn from_hosts(hosts: Vec<String>) -> Builder
pub fn from_hosts(hosts: Vec<String>) -> Builder
Starts building a consumer bootstraping internally a new kafka client from the given kafka hosts.
sourcepub fn client(&self) -> &KafkaClient
pub fn client(&self) -> &KafkaClient
Borrows the underlying kafka client.
sourcepub fn client_mut(&mut self) -> &mut KafkaClient
pub fn client_mut(&mut self) -> &mut KafkaClient
Borrows the underlying kafka client as mut.
sourcepub fn into_client(self) -> KafkaClient
pub fn into_client(self) -> KafkaClient
Destroys this consumer returning back the underlying kafka client.
sourcepub fn subscriptions(&self) -> HashMap<String, Vec<i32>>
pub fn subscriptions(&self) -> HashMap<String, Vec<i32>>
Retrieves the topic partitions being currently consumed by this consumer.
sourcepub fn poll(&mut self) -> Result<MessageSets>
pub fn poll(&mut self) -> Result<MessageSets>
Polls for the next available message data.
sourcepub fn group(&self) -> &str
pub fn group(&self) -> &str
Retrieves the group on which behalf this consumer is acting. The empty group name specifies a group-less consumer.
sourcepub fn last_consumed_message(&self, topic: &str, partition: i32) -> Option<i64>
pub fn last_consumed_message(&self, topic: &str, partition: i32) -> Option<i64>
Retrieves the offset of the last “consumed” message in the
specified partition. Results in None
if there is no such
“consumed” message.
sourcepub fn consume_message(
&mut self,
topic: &str,
partition: i32,
offset: i64,
) -> Result<()>
pub fn consume_message( &mut self, topic: &str, partition: i32, offset: i64, ) -> Result<()>
Marks the message at the specified offset in the specified topic partition as consumed by the caller.
Note: a message with a “later/higher” offset automatically marks all preceding messages as “consumed”, this is messages with “earlier/lower” offsets in the same partition. Therefore, it is not necessary to invoke this method for every consumed message.
Results in an error if the specified topic partition is not being consumed by this consumer.
sourcepub fn consume_messageset(&mut self, msgs: MessageSet<'_>) -> Result<()>
pub fn consume_messageset(&mut self, msgs: MessageSet<'_>) -> Result<()>
A convenience method to mark the given message set consumed as a whole by the caller. This is equivalent to marking the last message of the given set as consumed.
sourcepub fn commit_consumed(&mut self) -> Result<()>
pub fn commit_consumed(&mut self) -> Result<()>
Persists the so-far “marked as consumed” messages (on behalf of this consumer’s group for the underlying topic - if any.)
See also Consumer::consume_message
and
Consumer::consume_messageset
.