pub struct Consumer { /* private fields */ }Expand description
Subscribe-style consumer handle. Construct via Consumer::builder.
Implementations§
Source§impl Consumer
impl Consumer
Sourcepub async fn commit_sync(&self) -> Result<(), ConsumerError>
pub async fn commit_sync(&self) -> Result<(), ConsumerError>
Commit the current next-offsets for every assigned partition. Blocks until the broker acks.
Sourcepub fn commit_async(&self)
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
impl Consumer
Sourcepub 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>
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§impl Consumer
impl Consumer
Sourcepub fn generation_id(&self) -> i32
pub fn generation_id(&self) -> i32
The generation id captured at the most recent successful join.
Sourcepub fn group_metadata(&self) -> ConsumerGroupMetadata
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.
Sourcepub fn subscribed_topics(&self) -> &[String]
pub fn subscribed_topics(&self) -> &[String]
Topics this consumer subscribed to at build time.
Sourcepub async fn assignment(&self) -> Vec<(String, i32)>
pub async fn assignment(&self) -> Vec<(String, i32)>
Snapshot of currently assigned (topic, partition) pairs.
Sourcepub async fn close(self) -> Result<(), ConsumerError>
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
impl Consumer
Sourcepub async fn poll(
&mut self,
timeout: Duration,
) -> Result<Vec<ConsumerRecord>, ConsumerError>
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.