dgkafka 1.0.0a16__py3-none-any.whl → 1.0.0a17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dgkafka/consumer.py +28 -13
- {dgkafka-1.0.0a16.dist-info → dgkafka-1.0.0a17.dist-info}/METADATA +1 -1
- {dgkafka-1.0.0a16.dist-info → dgkafka-1.0.0a17.dist-info}/RECORD +6 -6
- {dgkafka-1.0.0a16.dist-info → dgkafka-1.0.0a17.dist-info}/WHEEL +0 -0
- {dgkafka-1.0.0a16.dist-info → dgkafka-1.0.0a17.dist-info}/licenses/LICENSE +0 -0
- {dgkafka-1.0.0a16.dist-info → dgkafka-1.0.0a17.dist-info}/top_level.txt +0 -0
dgkafka/consumer.py
CHANGED
@@ -66,9 +66,24 @@ class KafkaConsumer:
|
|
66
66
|
self._assign_topic_partition(topic, partition, offset)
|
67
67
|
else:
|
68
68
|
topics_list = [topics] if isinstance(topics, str) else topics
|
69
|
-
consumer.subscribe(topics_list)
|
70
|
-
|
71
|
-
|
69
|
+
consumer.subscribe(topics_list, on_assign=self.on_assign, on_revoke=self.on_revoke)
|
70
|
+
|
71
|
+
def on_assign(self, consumer, partitions):
|
72
|
+
self.kafka_status = "UP"
|
73
|
+
for topic in {p.topic for p in partitions}:
|
74
|
+
new = {p.partition for p in partitions if p.topic == topic}
|
75
|
+
self.logger.debug(f"[@] on_assign {topic} {new if new else '{}'}")
|
76
|
+
old = {p.partition for p in consumer.assignment() if p.topic == topic}
|
77
|
+
old.update(new)
|
78
|
+
self.logger.info(f"[*] Assigned {topic} {old if old else '{}'}")
|
79
|
+
|
80
|
+
def on_revoke(self, consumer, partitions):
|
81
|
+
for topic in {p.topic for p in partitions}:
|
82
|
+
new = {p.partition for p in partitions if p.topic == topic}
|
83
|
+
self.logger.debug(f"[@] on_revoke {topic} {new if new else '{}'}")
|
84
|
+
old = {p.partition for p in consumer.assignment() if p.topic == topic}
|
85
|
+
old.difference_update(new)
|
86
|
+
self.logger.info(f"[*] Assigned {topic} {old if old else '{}'}")
|
72
87
|
|
73
88
|
def _assign_topic_partition(self, topic: str, partition: int, offset: OffsetType) -> None:
|
74
89
|
"""Assign to specific partition"""
|
@@ -122,16 +137,16 @@ class KafkaConsumer:
|
|
122
137
|
consumer = self._ensure_consumer()
|
123
138
|
|
124
139
|
try:
|
125
|
-
# Получаем текущие подписки
|
126
|
-
subscribed_topics = consumer.subscription()
|
127
|
-
|
128
140
|
# Получаем текущие назначения (assignments)
|
129
141
|
assignments = consumer.assignment()
|
130
142
|
|
131
143
|
# Получаем текущие позиции (offsets)
|
132
144
|
current_offsets = []
|
133
145
|
if assignments:
|
134
|
-
current_offsets = consumer.position(assignments
|
146
|
+
current_offsets = [consumer.position(tp) for tp in assignments]
|
147
|
+
|
148
|
+
# Для получения подписок используем список топиков из assignments
|
149
|
+
subscribed_topics = list({tp.topic for tp in assignments}) if assignments else None
|
135
150
|
|
136
151
|
# Формируем информацию о назначениях
|
137
152
|
assignments_info = []
|
@@ -152,10 +167,11 @@ class KafkaConsumer:
|
|
152
167
|
})
|
153
168
|
|
154
169
|
return {
|
155
|
-
'subscribed_topics':
|
170
|
+
'subscribed_topics': subscribed_topics,
|
156
171
|
'assignments': assignments_info if assignments_info else None,
|
157
172
|
'current_offsets': offsets_info if offsets_info else None
|
158
173
|
}
|
174
|
+
|
159
175
|
except KafkaException as ex:
|
160
176
|
self.logger.error(f"[x] Failed to get subscription info: {ex}")
|
161
177
|
raise
|
@@ -170,13 +186,12 @@ class KafkaConsumer:
|
|
170
186
|
self.logger.info("[!] Not subscribed to any topics")
|
171
187
|
|
172
188
|
if info['assignments']:
|
173
|
-
self.logger.info("[*] Current assignments:")
|
189
|
+
self.logger.info("[*] Current partition assignments:")
|
174
190
|
for assignment in info['assignments']:
|
175
191
|
self.logger.info(f" - {assignment['topic']} [partition {assignment['partition']}]")
|
176
|
-
else:
|
177
|
-
self.logger.info("[!] No partition assignments")
|
178
192
|
|
179
193
|
if info['current_offsets']:
|
180
|
-
self.logger.info("[*] Current
|
194
|
+
self.logger.info("[*] Current read positions:")
|
181
195
|
for offset in info['current_offsets']:
|
182
|
-
self.logger.info(
|
196
|
+
self.logger.info(
|
197
|
+
f" - {offset['topic']} [partition {offset['partition']}]: position {offset['offset']}")
|
@@ -2,12 +2,12 @@ dgkafka/__init__.py,sha256=fnqVZROyHXipdmhqZaa9XUjvQe795JJKFakwTndAiIw,286
|
|
2
2
|
dgkafka/avro_consumer.py,sha256=fI-VYQdw3bQJoDN4jS0F5Aa78wlxmjg5lmnTumw9FDs,2917
|
3
3
|
dgkafka/avro_producer.py,sha256=UL0RBaEKl_lbNF1UI-4w8R3AIEGHYI-Vna3iVZIlJqo,5421
|
4
4
|
dgkafka/config.py,sha256=TmfB0IOauSPr4B8InOZdoebAEGeabs7HZUXuozAFFlk,3828
|
5
|
-
dgkafka/consumer.py,sha256=
|
5
|
+
dgkafka/consumer.py,sha256=OfONH61xj1sD4Z0YIQngfJOOwkx8Ko9waNYCKoXtJL4,8371
|
6
6
|
dgkafka/errors.py,sha256=PaH46tXameS--hrrUXKhQkZlBHvMSMPmjhVeRkmFvV0,95
|
7
7
|
dgkafka/json_consumer.py,sha256=7Gzn7C9WpyCTPDV6eFDugAx5gC9vdV-HrTh3Nv--zIE,1152
|
8
8
|
dgkafka/producer.py,sha256=WHVhw5HyJINxvUg_j_9iiQ0N7I3jc4niFXpZfkDHUOQ,6519
|
9
|
-
dgkafka-1.0.
|
10
|
-
dgkafka-1.0.
|
11
|
-
dgkafka-1.0.
|
12
|
-
dgkafka-1.0.
|
13
|
-
dgkafka-1.0.
|
9
|
+
dgkafka-1.0.0a17.dist-info/licenses/LICENSE,sha256=pAZXnNE2dxxwXFIduGyn1gpvPefJtUYOYZOi3yeGG94,1068
|
10
|
+
dgkafka-1.0.0a17.dist-info/METADATA,sha256=OML5JG3E8w6nYbMXUNMB_q3iSxplfy-g7y8FTMNosig,6062
|
11
|
+
dgkafka-1.0.0a17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
12
|
+
dgkafka-1.0.0a17.dist-info/top_level.txt,sha256=GyNrxOh7IPdL0t2SxH8DWxg3fUma-ezQ1Kz4zIr2B7U,8
|
13
|
+
dgkafka-1.0.0a17.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|