Skip to content

feat: add on_assign, on_revoke, on_lost callbacks for Confluent subscriber#2789

Merged
Lancetnik merged 1 commit intoag2ai:mainfrom
Br1an67:feat/confluent-rebalance-callbacks
Mar 1, 2026
Merged

feat: add on_assign, on_revoke, on_lost callbacks for Confluent subscriber#2789
Lancetnik merged 1 commit intoag2ai:mainfrom
Br1an67:feat/confluent-rebalance-callbacks

Conversation

@Br1an67
Copy link
Contributor

@Br1an67 Br1an67 commented Mar 1, 2026

Description

Add rebalance callback parameters (on_assign, on_revoke, on_lost) to the Confluent subscriber, allowing users to monitor partition assignment/revocation events without monkey-patching AsyncConfluentConsumer.

These callbacks are passed directly to confluent_kafka.Consumer.subscribe().

Usage:

@broker.subscriber(
    "my-topic",
    on_assign=lambda consumer, partitions: print(f"Assigned: {partitions}"),
    on_revoke=lambda consumer, partitions: print(f"Revoked: {partitions}"),
    on_lost=lambda consumer, partitions: print(f"Lost: {partitions}"),
)
async def handler(body: str):
    print(body)

Fixes #1676

Type of change

  • New feature (a non-breaking change that adds functionality)

Checklist

  • My code adheres to the style guidelines of this project (just lint shows no errors)
  • I have conducted a self-review of my own code
  • I have made the necessary changes to the documentation
  • My changes do not generate any new warnings
  • I have added tests to validate the effectiveness of my fix or the functionality of my new feature
  • Both new and existing unit tests pass successfully on my local environment by running just test-coverage
  • I have ensured that static analysis tests are passing by running just static-analysis
  • I have included code examples to illustrate the modifications

…riber

Add rebalance callback parameters to the Confluent subscriber, allowing
users to specify on_assign, on_revoke, and on_lost callbacks that are
passed through to confluent_kafka.Consumer.subscribe().

This enables monitoring partition assignment/revocation events without
monkey-patching AsyncConfluentConsumer.

Fixes ag2ai#1676
@Lancetnik Lancetnik enabled auto-merge March 1, 2026 07:30
@Lancetnik Lancetnik added this pull request to the merge queue Mar 1, 2026
Merged via the queue into ag2ai:main with commit 31fcbc1 Mar 1, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Confluent Issues related to `faststream.confluent` module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add ability to specify on_assign, on_revoke, and on_lost callbacks for a Confluent subscriber

2 participants