Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX add error_cb to confluent.Consumer config in ConsumerFromTopic #44307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions providers/src/airflow/providers/apache/kafka/hooks/consume.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
from airflow.providers.apache.kafka.hooks.base import KafkaBaseHook


class KafkaAuthenticationError(Exception):
"""Custom exception for Kafka authentication failures."""

pass


def error_callback(err):
"""Handle kafka errors."""
print("Exception received: ", err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we try to use logger instead of a print here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think in other operators they use logger instead

raise KafkaAuthenticationError(f"Authentication failed: {err}")


class KafkaConsumerHook(KafkaBaseHook):
"""
A hook for creating a Kafka Consumer.
Expand All @@ -36,6 +48,7 @@ def __init__(self, topics: Sequence[str], kafka_config_id=KafkaBaseHook.default_
self.topics = topics

def _get_client(self, config) -> Consumer:
config["error_cb"] = error_callback
return Consumer(config)

def get_consumer(self) -> Consumer:
Expand Down
Loading