providers.akafka.KafkaEventSubscriber

Apache Kafka-specific event subscription provider.

Usage

Source

providers.akafka.KafkaEventSubscriber()

Classes

Name Description
RetriesExhaustedError Raised when an event has been retried the maximum number of times.
RetriesLeftError Raised when the value for retries_left is invalid.

RetriesExhaustedError

Raised when an event has been retried the maximum number of times.

Usage

Source

RetriesExhaustedError()


RetriesLeftError

Raised when the value for retries_left is invalid.

Usage

Source

RetriesLeftError()

Methods

Name Description
__init__() Please do not call directly! Should be called by the construct method.
construct() Setup and teardown KafkaEventSubscriber instance with some config params.
run() Start consuming events and passing them down to the translator.

__init__()

Please do not call directly! Should be called by the construct method.

Usage

Source

__init__(*, consumer, translator, config, dlq_publisher=None)

Parameters

consumer

hands over a started AIOKafkaConsumer. translator (EventSubscriberProtocol): The translator that translates between the protocol (mentioned in the type annotation) and an application-specific port (according to the triple hexagonal architecture).

dlq_publisher

A running instance of a publishing provider that implements the EventPublisherProtocol, such as KafkaEventPublisher. Can be None if not using the dead letter queue. It is used to publish events to the DLQ.

config

The KafkaConfig instance


construct()

Setup and teardown KafkaEventSubscriber instance with some config params.

Usage

Source

construct(
    *,
    config,
    translator,
    kafka_consumer_cls=AIOKafkaConsumer,
    dlq_publisher=None
)
Parameters
config: KafkaConfig

Config parameters needed for connecting to Apache Kafka.

translator: EventSubscriberProtocol

The translator that translates between the protocol (mentioned in the type annotation) and an application-specific port (according to the triple hexagonal architecture).

dlq_publisher: EventPublisherProtocol | None = None

A running instance of a publishing provider that implements the EventPublisherProtocol, such as KafkaEventPublisher. Can be None if not using the dead letter queue. It is used to publish events to the DLQ.

kafka_consumer_cls: type[KafkaConsumerCompatible] = AIOKafkaConsumer
Overwrite the used Kafka consumer class. Only intended for unit testing.


run()

Start consuming events and passing them down to the translator.

Usage

Source

run(forever=True)

By default, this method blocks forever. However, you can set forever to False to make it return after handling one event.