Skip to main content

ConsumerRebalanceListener

Trait ConsumerRebalanceListener 

Source
pub trait ConsumerRebalanceListener: Send + Sync {
    // Required methods
    fn on_partitions_revoked<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        consumer: &'life1 Consumer,
        partitions: &'life2 [(String, i32)],
    ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn on_partitions_assigned<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        consumer: &'life1 Consumer,
        partitions: &'life2 [(String, i32)],
    ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided method
    fn on_partitions_lost<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        consumer: &'life1 Consumer,
        partitions: &'life2 [(String, i32)],
    ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Callbacks for the partitions that a rebalance takes from or gives to the consumer. Kafka’s ConsumerRebalanceListener.

The consumer calls them inside Consumer::poll and Consumer::close, in this order:

  • Eager protocol: on_partitions_revoked with all owned partitions before the JoinGroup, then on_partitions_assigned with the new assignment.
  • Cooperative protocol: after the SyncGroup, on_partitions_revoked with the partitions that left the assignment, only when there are some, then on_partitions_assigned with the added partitions, also when there are none.
  • on_partitions_lost in place of on_partitions_revoked when the member lost its generation: UNKNOWN_MEMBER_ID, FENCED_INSTANCE_ID or max_poll_interval.

Each list is sorted by topic and partition. A callback can use the consumer, for example to commit with Consumer::commit_sync from on_partitions_revoked. An error from a callback makes that poll return ConsumerError::RebalanceListenerFailed after the rebalance step.

Required Methods§

Source

fn on_partitions_revoked<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, consumer: &'life1 Consumer, partitions: &'life2 [(String, i32)], ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Kafka’s onPartitionsRevoked.

§Errors

An error that poll returns.

Source

fn on_partitions_assigned<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, consumer: &'life1 Consumer, partitions: &'life2 [(String, i32)], ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Kafka’s onPartitionsAssigned.

§Errors

An error that poll returns.

Provided Methods§

Source

fn on_partitions_lost<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, consumer: &'life1 Consumer, partitions: &'life2 [(String, i32)], ) -> Pin<Box<dyn Future<Output = Result<(), RebalanceListenerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Kafka’s onPartitionsLost. The default calls on_partitions_revoked, as in Kafka.

§Errors

An error that poll returns.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§