kafka::consumer

Struct Consumer

source
pub struct Consumer { /* private fields */ }
Expand description

The Kafka Consumer

See module level documentation.

Implementations§

source§

impl Consumer

source

pub fn from_client(client: KafkaClient) -> Builder

Starts building a consumer using the given kafka client.

source

pub fn from_hosts(hosts: Vec<String>) -> Builder

Starts building a consumer bootstraping internally a new kafka client from the given kafka hosts.

source

pub fn client(&self) -> &KafkaClient

Borrows the underlying kafka client.

source

pub fn client_mut(&mut self) -> &mut KafkaClient

Borrows the underlying kafka client as mut.

source

pub fn into_client(self) -> KafkaClient

Destroys this consumer returning back the underlying kafka client.

source

pub fn subscriptions(&self) -> HashMap<String, Vec<i32>>

Retrieves the topic partitions being currently consumed by this consumer.

source

pub fn poll(&mut self) -> Result<MessageSets>

Polls for the next available message data.

source

pub fn group(&self) -> &str

Retrieves the group on which behalf this consumer is acting. The empty group name specifies a group-less consumer.

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl Debug for Consumer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more