-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
86 lines (73 loc) · 2.91 KB
/
Copy pathconfig.py
File metadata and controls
86 lines (73 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Types used in this library"""
from dataclasses import dataclass, field
from typing import Callable, Any
@dataclass(kw_only=True)
class _CommonConfig:
"""
Topic configuration common for consumers and producers.
Attributes:
kafka_hosts: list of Kafka node URLs to connect to
username: Kafka username
password: Kafka password
additional_settings: additional settings to pass directly to Kafka
"""
kafka_hosts: list[str]
username: str
password: str
additional_settings: dict[str, Any] = field(default_factory=dict)
@dataclass
class ProducerConfig(_CommonConfig):
"""
Topic configuration common each producer, including backoff settings.
Attributes:
kafka_hosts: list of Kafka node URLs to connect to
topics: list of topic names to publish to
username: producer username
password: producer password
additional_settings: additional settings to pass directly to Kafka consumer
retries: number of attempts to publish the message
fallback_factor: how many times longer should each backoff take
fallback_base: what is the starting backoff in seconds
"""
topics: list[str]
retries: int = field(default=3)
fallback_factor: float = field(default=2.0)
fallback_base: float = field(default=5.0)
@dataclass
class ConsumeTopicConfig:
"""
Configuration for retry mechanism of a consumer.
Must be used from within ConsumerConfig.
Attributes:
base_topic: Topic that this consumer subscribes to
retry_topic: Topic used for resending failed messages
retries: maximal number of attempts to re-process the
message originated from base_topic
fallback_delay: Number of seconds to wait before a message
should be re-processed. This is a non-blocking event.
"""
base_topic: str
retry_topic: str | None = field(default=None)
retries: int = field(default=5)
fallback_delay: float = field(default=15.0)
@dataclass
class ConsumerConfig(_CommonConfig):
"""
Topic configuration for each consumer.
Attributes:
kafka_hosts: list of Kafka node URLs to connect to
topics: list of configuration for topics and their
retry policies
cancel_future_wait_time: Maximal time to wait fot a task
to finish before discarding it on rebalance or soft shutdown.
Doesn't affect tasks which are ran in normal circumstances.
username: consumer username
password: consumer password
additional_settings: additional settings to pass directly to Kafka producer
group_id: consumer group ID to use when consuming
target: Callable to execute on all parsed messages
"""
group_id: str
target: Callable[[dict[str, Any]], Any]
topics: list[ConsumeTopicConfig] = field(default_factory=list)
cancel_future_wait_time: float = field(default=30.0)