|
1 | 1 | from dataclasses import dataclass
|
2 |
| -from typing import Generic, NamedTuple, Optional, Sequence, Tuple, TypeVar |
| 2 | +from typing import Generic, List, NamedTuple, Optional, Sequence, Tuple, TypeVar |
3 | 3 |
|
4 |
| -from kafka.structs import ( |
5 |
| - BrokerMetadata, |
6 |
| - OffsetAndMetadata, |
7 |
| - PartitionMetadata, |
8 |
| - TopicPartition, |
9 |
| -) |
| 4 | +from aiokafka.errors import KafkaError |
10 | 5 |
|
11 | 6 |
|
12 | 7 | __all__ = [
|
|
19 | 14 | ]
|
20 | 15 |
|
21 | 16 |
|
| 17 | +class TopicPartition(NamedTuple): |
| 18 | + """A topic and partition tuple""" |
| 19 | + |
| 20 | + topic: str |
| 21 | + "A topic name" |
| 22 | + |
| 23 | + partition: int |
| 24 | + "A partition id" |
| 25 | + |
| 26 | + |
| 27 | +class BrokerMetadata(NamedTuple): |
| 28 | + """A Kafka broker metadata used by admin tools""" |
| 29 | + |
| 30 | + nodeId: int |
| 31 | + "The Kafka broker id" |
| 32 | + |
| 33 | + host: str |
| 34 | + "The Kafka broker hostname" |
| 35 | + |
| 36 | + port: int |
| 37 | + "The Kafka broker port" |
| 38 | + |
| 39 | + rack: Optional[str] |
| 40 | + """The rack of the broker, which is used to in rack aware partition |
| 41 | + assignment for fault tolerance. |
| 42 | + Examples: `RACK1`, `us-east-1d`. Default: None |
| 43 | + """ |
| 44 | + |
| 45 | + |
| 46 | +class PartitionMetadata(NamedTuple): |
| 47 | + """A topic partition metadata describing the state in the MetadataResponse""" |
| 48 | + |
| 49 | + topic: str |
| 50 | + "The topic name of the partition this metadata relates to" |
| 51 | + |
| 52 | + partition: int |
| 53 | + "The id of the partition this metadata relates to" |
| 54 | + |
| 55 | + leader: int |
| 56 | + "The id of the broker that is the leader for the partition" |
| 57 | + |
| 58 | + replicas: List[int] |
| 59 | + "The ids of all brokers that contain replicas of the partition" |
| 60 | + isr: List[int] |
| 61 | + "The ids of all brokers that contain in-sync replicas of the partition" |
| 62 | + |
| 63 | + error: Optional[KafkaError] |
| 64 | + "A KafkaError object associated with the request for this partition metadata" |
| 65 | + |
| 66 | + |
| 67 | +class OffsetAndMetadata(NamedTuple): |
| 68 | + """The Kafka offset commit API |
| 69 | +
|
| 70 | + The Kafka offset commit API allows users to provide additional metadata |
| 71 | + (in the form of a string) when an offset is committed. This can be useful |
| 72 | + (for example) to store information about which node made the commit, |
| 73 | + what time the commit was made, etc. |
| 74 | + """ |
| 75 | + |
| 76 | + offset: int |
| 77 | + "The offset to be committed" |
| 78 | + |
| 79 | + metadata: str |
| 80 | + "Non-null metadata" |
| 81 | + |
| 82 | + # TODO add leaderEpoch: |
| 83 | + |
| 84 | + |
22 | 85 | class RecordMetadata(NamedTuple):
|
23 | 86 | """Returned when a :class:`~.AIOKafkaProducer` sends a message"""
|
24 | 87 |
|
|
0 commit comments