Skip to main content

Consumer

Struct Consumer 

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

Subscribe-style consumer handle. Construct via Consumer::builder.

Implementations§

Source§

impl Consumer

Source

pub async fn commit_sync(&self) -> Result<(), ConsumerError>

Commit the current next-offsets for every assigned partition. Blocks until the broker acks.

Source

pub fn commit_async(&self)

Fire-and-forget commit. Returns once the request is enqueued on the client’s writer task; does NOT wait for the broker ack. Errors are logged but not returned.

Source§

impl Consumer

Source

pub async fn start( bootstrap: String, client_id: String, group_id: String, session_timeout: Duration, rebalance_timeout: Duration, heartbeat_interval: Duration, subscribe: Vec<String>, auto_offset_reset: AutoOffsetReset, isolation_level: IsolationLevel, assignor: Assignor, client_rack: Option<String>, security: Option<ClientSecurity>, ) -> Result<Self, ConsumerError>

Build a Consumer subscribed to the given topics: resolve bootstrap, JoinGroup (twice), compute the assignment if we’re the elected leader, SyncGroup, prime offsets, then spawn the coordinator task that owns the heartbeat + rebalance loop.

Source

pub fn builder() -> ConsumerStartBuilder

Build a Consumer subscribed to the given topics: resolve bootstrap, JoinGroup (twice), compute the assignment if we’re the elected leader, SyncGroup, prime offsets, then spawn the coordinator task that owns the heartbeat + rebalance loop.

Source§

impl Consumer

Source

pub fn group_id(&self) -> &str

The consumer’s group id.

Source

pub fn member_id(&self) -> &str

The member id assigned by the coordinator at join time.

Source

pub fn generation_id(&self) -> i32

The generation id captured at the most recent successful join.

Source

pub fn group_metadata(&self) -> ConsumerGroupMetadata

KIP-447 group metadata to hand to a transactional producer’s send_offsets_to_transaction. The generation id is the value captured at the most recent successful join (the field is not kept in sync as the coordinator rejoins — see Self::generation_id); for a stable single-member group this equals the coordinator’s live generation. group_instance_id is always None — the consumer has no static-membership support yet.

Source

pub fn subscribed_topics(&self) -> &[String]

Topics this consumer subscribed to at build time.

Source

pub async fn assignment(&self) -> Vec<(String, i32)>

Snapshot of currently assigned (topic, partition) pairs.

Source

pub async fn close(self) -> Result<(), ConsumerError>

Stop the coordinator task so the broker evicts this member promptly.

The coordinator itself sends a best-effort LeaveGroup as the last thing it does on shutdown (see crate::coordinator::run), using its live member_id. That id can differ from the one captured at build time — a from-scratch rejoin (UNKNOWN_MEMBER_ID) replaces it — so the leave must come from the coordinator, which owns the current value; sending it here with self.member_id would silently leave a stale id and orphan the real member until its session expires. Cancel + join is prompt because the coordinator races its in-tick RPCs against the shutdown token.

Source§

impl Consumer

Source

pub async fn poll( &mut self, timeout: Duration, ) -> Result<Vec<ConsumerRecord>, ConsumerError>

Returns the records from every v2 batch the broker returned per assigned partition, or an empty vec on timeout. Under read_committed isolation, control batches and records belonging to aborted transactions are filtered client-side using the response’s aborted_transactions list (the broker returns verbatim bytes). Rebalances are handled transparently by the internal coordinator task, which mutates the live assigned snapshot in place; poll() simply reads it on each call.

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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