44from typing import Callable , Any
55
66
7- @dataclass
7+ @dataclass ( kw_only = True )
88class _CommonConfig :
99 """
1010 Topic configuration common for consumers and producers.
1111 Attributes:
1212 kafka_hosts: list of Kafka node URLs to connect to
13- topics: list of topic names to connect to
1413 username: Kafka username
1514 password: Kafka password
15+ additional_settings: additional settings to pass directly to Kafka
1616 """
1717
1818 kafka_hosts : list [str ]
19- topics : list [str ]
2019 username : str
2120 password : str
21+ additional_settings : dict [str , Any ] = field (default_factory = dict )
2222
2323
2424@dataclass
@@ -30,28 +30,57 @@ class ProducerConfig(_CommonConfig):
3030 topics: list of topic names to publish to
3131 username: producer username
3232 password: producer password
33+ additional_settings: additional settings to pass directly to Kafka consumer
3334 retries: number of attempts to publish the message
3435 fallback_factor: how many times longer should each backoff take
3536 fallback_base: what is the starting backoff in seconds
3637 """
3738
39+ topics : list [str ]
3840 retries : int = field (default = 3 )
3941 fallback_factor : float = field (default = 2.0 )
4042 fallback_base : float = field (default = 5.0 )
4143
4244
45+ @dataclass
46+ class ConsumeTopicConfig :
47+ """
48+ Configuration for retry mechanism of a consumer.
49+ Must be used from within ConsumerConfig.
50+ Attributes:
51+ base_topic: Topic that this consumer subscribes to
52+ retry_topic: Topic used for resending failed messages
53+ retries: maximal number of attempts to re-process the
54+ message originated from base_topic
55+ fallback_delay: Number of seconds to wait before a message
56+ should be re-processed. This is a non-blocking event.
57+ """
58+
59+ base_topic : str
60+ retry_topic : str | None = field (default = None )
61+ retries : int = field (default = 5 )
62+ fallback_delay : float = field (default = 15.0 )
63+
64+
4365@dataclass
4466class ConsumerConfig (_CommonConfig ):
4567 """
4668 Topic configuration for each consumer.
4769 Attributes:
4870 kafka_hosts: list of Kafka node URLs to connect to
49- topics: list of topic names to connect to
71+ topics: list of configuration for topics and their
72+ retry policies
73+ cancel_future_wait_time: Maximal time to wait for a task
74+ to finish before discarding it on rebalance or soft shutdown.
75+ Doesn't affect tasks which are ran in normal circumstances.
5076 username: consumer username
5177 password: consumer password
78+ additional_settings: additional settings to pass directly to Kafka producer
5279 group_id: consumer group ID to use when consuming
5380 target: Callable to execute on all parsed messages
5481 """
5582
5683 group_id : str
5784 target : Callable [[dict [str , Any ]], Any ]
85+ topics : list [ConsumeTopicConfig ] = field (default_factory = list )
86+ cancel_future_wait_time : float = field (default = 30.0 )
0 commit comments