pub struct ShareConsumer { /* private fields */ }Expand description
A share-group consumer. Construct via ShareConsumer::builder.
It joins the group and keeps the membership alive with a background
heartbeat. poll issues ShareFetch over the live
assignment and returns the acquired records. Acknowledgement, implicit or
explicit per ShareAckMode, travels back to the broker on the next
ShareFetch as a piggyback, or in a standalone ShareAcknowledge from
commit.
Implementations§
Sourcepub async fn start(
bootstrap: String,
client_id: String,
group_id: String,
subscribe: Vec<String>,
ack_mode: ShareAckMode,
acquire_mode: ShareAcquireMode,
fetch_min: i32,
fetch_max: i32,
fetch_max_records: i32,
heartbeat_interval: Time,
leave_heartbeat_timeout: Time,
dispatch_queue_capacity: usize,
frame_max: ByteSize,
metadata_recovery_strategy: MetadataRecoveryStrategy,
metadata_recovery_rebootstrap_trigger: Time,
security: Option<ClientSecurity>,
allow_auto_create_topics: bool,
enable_metrics_push: bool,
) -> Result<Self, ConsumerError>
pub async fn start( bootstrap: String, client_id: String, group_id: String, subscribe: Vec<String>, ack_mode: ShareAckMode, acquire_mode: ShareAcquireMode, fetch_min: i32, fetch_max: i32, fetch_max_records: i32, heartbeat_interval: Time, leave_heartbeat_timeout: Time, dispatch_queue_capacity: usize, frame_max: ByteSize, metadata_recovery_strategy: MetadataRecoveryStrategy, metadata_recovery_rebootstrap_trigger: Time, security: Option<ClientSecurity>, allow_auto_create_topics: bool, enable_metrics_push: bool, ) -> Result<Self, ConsumerError>
Join a share group and start heartbeating.
This method sends one ShareGroupHeartbeat that carries a client-generated
member UUID, epoch 0, and subscribe. It captures the returned member id, epoch,
heartbeat interval, and assignment. It resolves the assignment topic ids
→ names with Metadata, then spawns the heartbeat loop.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Sourcepub fn builder() -> ShareConsumerStartBuilder
pub fn builder() -> ShareConsumerStartBuilder
Join a share group and start heartbeating.
This method sends one ShareGroupHeartbeat that carries a client-generated
member UUID, epoch 0, and subscribe. It captures the returned member id, epoch,
heartbeat interval, and assignment. It resolves the assignment topic ids
→ names with Metadata, then spawns the heartbeat loop.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Sourcepub fn member_id(&self) -> &str
pub fn member_id(&self) -> &str
The client-generated member id returned by the broker at join time.
Sourcepub async fn assignment(&self) -> Vec<(String, i32)>
pub async fn assignment(&self) -> Vec<(String, i32)>
Snapshot of the currently assigned (topic, partition) pairs.
Sourcepub async fn close(&mut self) -> Result<(), ConsumerError>
pub async fn close(&mut self) -> Result<(), ConsumerError>
Stop heartbeating, acknowledge outstanding records, and leave the group.
This method first flushes any outstanding acknowledgements in a
standalone ShareAcknowledge. In Implicit mode it auto-Accepts the
previous poll’s delivered ranges. In Explicit mode it sends any staged
acknowledge() calls. It then cancels the heartbeat task and awaits it.
The task sends a best-effort leave heartbeat with member_epoch = -1 on
its way out, so the broker evicts this member promptly and does not wait
out the session timeout. A flush failure is best-effort and logged, so
close still leaves the group. Last, it sends the terminating
telemetry push (KIP-714) when the consumer pushes metrics and has a
subscription.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Sourcepub async fn client_instance_id(
&self,
timeout: Time,
) -> Result<Option<Uuid>, ConsumerError>
pub async fn client_instance_id( &self, timeout: Time, ) -> Result<Option<Uuid>, ConsumerError>
The client instance id that the broker assigned for metrics push
(KIP-714), as Kafka’s KafkaShareConsumer.clientInstanceId returns
it.
The call waits up to timeout for the first
GetTelemetrySubscriptions response. It returns Ok(None) when none
has come by then, as Kafka returns null. A zero timeout does not
wait.
§Errors
Returns ClientError::TelemetryDisabled when enable_metrics_push
is false, and ClientError::InvalidArgument for a negative
timeout, as Kafka throws an IllegalStateException and an
IllegalArgumentException.
Sourcepub async fn poll(
&mut self,
timeout: Time,
) -> Result<Vec<ShareConsumerRecord>, ConsumerError>
pub async fn poll( &mut self, timeout: Time, ) -> Result<Vec<ShareConsumerRecord>, ConsumerError>
Acquire and return the next batch of records.
This method piggybacks the acknowledgements for the previous poll() on
the ShareFetch. Those are the implicit auto-Accept ranges, or the
drained explicit acknowledge() calls. It then decodes the acquired
records and pairs each one with the broker-reported delivery_count
from its acquired_records range.
With no assignment yet, this method waits for the heartbeat loop to
assign partitions within timeout. The fetch uses the remaining wait
budget. If the assignment stays empty, it returns empty at the deadline.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Sourcepub fn acknowledge(
&mut self,
record: &ShareConsumerRecord,
ack: ShareAckType,
) -> Result<(), ConsumerError>
pub fn acknowledge( &mut self, record: &ShareConsumerRecord, ack: ShareAckType, ) -> Result<(), ConsumerError>
Stage an explicit acknowledgement for record, in Explicit mode.
The next poll flushes the ack as a piggyback,
or commit flushes it in a standalone
ShareAcknowledge.
§Errors
Returns ConsumerError::IllegalState in
Implicit mode. In that mode the
next poll or close auto-Accepts every delivered record, so this method
cannot honor an explicit acknowledge(). Staging it would silently leak
into pending_acks, which the implicit path never flushes. This mirrors
the JVM KafkaShareConsumer, which raises IllegalStateException if you
explicitly acknowledge while in implicit acknowledgement mode.
Sourcepub async fn renew(
&mut self,
record: &ShareConsumerRecord,
) -> Result<(), ConsumerError>
pub async fn renew( &mut self, record: &ShareConsumerRecord, ) -> Result<(), ConsumerError>
Renew the acquisition lock on a single delivered record (KIP-1222).
This method sends a standalone ShareAcknowledge with
is_renew_ack = true and acknowledge_types = [4] for the record’s
offset. The Renew wire type extends the broker-side lock deadline without
changing the record’s state. Like acknowledge,
this is only valid in explicit ack mode. It advances the session epoch on
success.
§Errors
Returns ConsumerError::IllegalState in
Implicit mode, where the next
poll or close auto-accepts the records, so a lock renewal is meaningless.
Returns ConsumerError::Server if the broker rejects the renew.
Sourcepub async fn commit(&mut self) -> Result<(), ConsumerError>
pub async fn commit(&mut self) -> Result<(), ConsumerError>
Flush the staged explicit acknowledgements in a standalone
ShareAcknowledge. This is a no-op when nothing is staged.
§Errors
Returns an error when configuration is invalid, protocol encoding fails, the broker rejects the request, or transport I/O fails.
Auto Trait Implementations§
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);