## providers.akafka.KafkaEventSubscriber

<span id="hexkit.providers.akafka.KafkaEventSubscriber"></span>


Apache Kafka-specific event subscription provider.


Usage

``` python
providers.akafka.KafkaEventSubscriber(
    *, consumer, translator, config, dlq_publisher=None
)
```


## Classes

| Name | Description |
|----|----|
| [RetriesExhaustedError](#RetriesExhaustedError) | Raised when an event has been retried the maximum number of times. |
| [RetriesLeftError](#RetriesLeftError) | Raised when the value for `retries_left` is invalid. |

<span id="RetriesExhaustedError"></span>

<span id="hexkit.providers.akafka.KafkaEventSubscriber.RetriesExhaustedError"></span>


#### RetriesExhaustedError


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


Usage

``` python
RetriesExhaustedError(*, event_type, max_retries)
```


<span id="RetriesLeftError"></span>

<span id="hexkit.providers.akafka.KafkaEventSubscriber.RetriesLeftError"></span>

------------------------------------------------------------------------


#### RetriesLeftError


Raised when the value for `retries_left` is invalid.


Usage

``` python
RetriesLeftError(*, retries_left, max_retries)
```


## Methods

| Name | Description |
|----|----|
| [__init__()](#__init__) | Please do not call directly! Should be called by the [construct](providers.mongodb.MongoDbDaoFactory.md#hexkit.providers.mongodb.MongoDbDaoFactory.construct) method. |
| [construct()](#construct) | Setup and teardown KafkaEventSubscriber instance with some config params. |
| [run()](#run) | Start consuming events and passing them down to the translator. |

<span id="__init__"></span>

<span id="hexkit.providers.akafka.KafkaEventSubscriber.__init__"></span>


#### \_\_init\_\_()


Please do not call directly! Should be called by the [construct](providers.mongodb.MongoDbDaoFactory.md#hexkit.providers.mongodb.MongoDbDaoFactory.construct) method.


Usage

``` python
__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


<span id="hexkit.providers.akafka.KafkaEventSubscriber.construct"></span>

------------------------------------------------------------------------


#### construct()


Setup and teardown KafkaEventSubscriber instance with some config params.


Usage

``` python
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.


<span id="hexkit.providers.akafka.KafkaEventSubscriber.run"></span>

------------------------------------------------------------------------


#### run()


Start consuming events and passing them down to the translator.


Usage

``` python
run(forever=True)
```


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