pub struct StreamsGroupSession { /* private fields */ }Expand description
An active Kafka Streams group membership session.
A session starts by sending API 88 with a client-generated member ID, member
epoch zero, and the configured topology. Subsequent calls send the current
member epoch and only transmit changed membership data according to Kafka’s
nullable protocol fields. Call Self::close to leave gracefully.
Implementations§
Source§impl StreamsGroupSession
impl StreamsGroupSession
Sourcepub async fn join(config: StreamsGroupConfig) -> Result<Self>
pub async fn join(config: StreamsGroupConfig) -> Result<Self>
Joins the configured Kafka Streams group.
Sourcepub fn member_id(&self) -> &str
pub fn member_id(&self) -> &str
Returns the client-generated member ID used for this Streams session.
Sourcepub fn member_epoch(&self) -> i32
pub fn member_epoch(&self) -> i32
Returns the current member epoch.
Sourcepub fn heartbeat_interval(&self) -> Duration
pub fn heartbeat_interval(&self) -> Duration
Returns the broker-requested heartbeat interval.
Sourcepub fn assignment(&self) -> &StreamsGroupSessionAssignment
pub fn assignment(&self) -> &StreamsGroupSessionAssignment
Returns the latest successful assignment snapshot.
A None collection means that Kafka omitted the nullable field in its
response; it is distinct from Some(Vec::new()), which is an explicit
empty assignment.
Sourcepub fn set_task_state(
&mut self,
active_tasks: Vec<StreamsGroupHeartbeatTask>,
standby_tasks: Vec<StreamsGroupHeartbeatTask>,
warmup_tasks: Vec<StreamsGroupHeartbeatTask>,
task_offsets: Vec<StreamsGroupHeartbeatTaskOffset>,
task_end_offsets: Vec<StreamsGroupHeartbeatTaskOffset>,
)
pub fn set_task_state( &mut self, active_tasks: Vec<StreamsGroupHeartbeatTask>, standby_tasks: Vec<StreamsGroupHeartbeatTask>, warmup_tasks: Vec<StreamsGroupHeartbeatTask>, task_offsets: Vec<StreamsGroupHeartbeatTaskOffset>, task_end_offsets: Vec<StreamsGroupHeartbeatTaskOffset>, )
Replaces the task state and changelog offsets reported on the next heartbeat.
Empty vectors are meaningful and are sent as empty compact arrays. The values remain pending until a heartbeat succeeds, so a reconnect does not silently lose a task-state update.
Sourcepub fn set_task_state_with_optional_offsets(
&mut self,
active_tasks: Vec<StreamsGroupHeartbeatTask>,
standby_tasks: Vec<StreamsGroupHeartbeatTask>,
warmup_tasks: Vec<StreamsGroupHeartbeatTask>,
task_offsets: Option<Vec<StreamsGroupHeartbeatTaskOffset>>,
task_end_offsets: Option<Vec<StreamsGroupHeartbeatTaskOffset>>,
)
pub fn set_task_state_with_optional_offsets( &mut self, active_tasks: Vec<StreamsGroupHeartbeatTask>, standby_tasks: Vec<StreamsGroupHeartbeatTask>, warmup_tasks: Vec<StreamsGroupHeartbeatTask>, task_offsets: Option<Vec<StreamsGroupHeartbeatTaskOffset>>, task_end_offsets: Option<Vec<StreamsGroupHeartbeatTaskOffset>>, )
Replaces task state while optionally omitting changelog offsets.
Kafka 4.3 currently rejects non-null task-offset fields for some Streams
group configurations. Passing None preserves the protocol’s nullable
field semantics and lets the broker request offsets when supported.
Sourcepub async fn heartbeat(&mut self) -> Result<StreamsGroupHeartbeatResponseV0>
pub async fn heartbeat(&mut self) -> Result<StreamsGroupHeartbeatResponseV0>
Sends one Streams heartbeat and returns the broker’s assignment state.
Coordinator transport failures and member/coordinator epoch errors are recovered within the configured retry budget. A rejoin resends the initial topology and updates the session’s member identity.
Sourcepub fn spawn_heartbeat_task(self) -> StreamsGroupSessionHandle
pub fn spawn_heartbeat_task(self) -> StreamsGroupSessionHandle
Moves this session into a background heartbeat task.
The session must already be joined. The task sends heartbeats using the
interval most recently returned by Kafka, publishes every successful
assignment through StreamsGroupSessionHandle::subscribe_assignment,
and preserves the existing bounded retry and rejoin behavior.