__init__.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. from asyncio.events import AbstractEventLoop
  2. from collections import namedtuple
  3. from kafka.structs import ConsumerRecord
  4. from kafka.structs import TopicPartition
  5. from typing import Any
  6. from typing import AsyncIterator
  7. from typing import Awaitable
  8. from typing import Dict
  9. from typing import List
  10. from typing import Optional
  11. from typing import Set
  12. from typing import Tuple
  13. class AIOKafkaProducer:
  14. _sender: Any
  15. def __init__(
  16. self,
  17. bootstrap_servers: List[str],
  18. loop: AbstractEventLoop,
  19. enable_auto_commit: Optional[bool] = True,
  20. group_id: Optional[str] = None,
  21. api_version: str = "auto",
  22. ):
  23. ...
  24. async def send(
  25. self,
  26. topic_id: str,
  27. value: bytes,
  28. key: Optional[bytes] = None,
  29. headers: Optional[List[Tuple[str, bytes]]] = None,
  30. ) -> Awaitable[ConsumerRecord]:
  31. ...
  32. async def start(self) -> None:
  33. ...
  34. async def stop(self) -> None:
  35. ...
  36. async def flush(self) -> None:
  37. ...
  38. class AIOKafkaClient:
  39. async def ready(self, node_id: str, *, group: Optional[str] = None) -> bool:
  40. ...
  41. class GroupCoordinator:
  42. coordinator_id: str
  43. def request_rejoin(self) -> None:
  44. ...
  45. def need_rejoin(self, subscription: "Subscription") -> bool:
  46. ...
  47. async def ensure_coordinator_known(self) -> None:
  48. ...
  49. async def ensure_active_group(self, subscription: Any, assignment: Any) -> None:
  50. ...
  51. class Subscription:
  52. subscription: Any
  53. async def wait_for_subscription(self) -> None:
  54. ...
  55. async def partitions_auto_assigned(self) -> bool:
  56. ...
  57. class AIOKafkaConsumer:
  58. _client: AIOKafkaClient
  59. _coordinator: GroupCoordinator
  60. _subscription: Subscription
  61. _group_id: Optional[str]
  62. def __init__(
  63. self,
  64. bootstrap_servers: List[str],
  65. loop: AbstractEventLoop,
  66. group_id: Optional[str],
  67. api_version: str = "auto",
  68. **kwargs: Any,
  69. ):
  70. ...
  71. async def getone(self, *partitions: Optional[List[TopicPartition]]) -> ConsumerRecord:
  72. ...
  73. async def subscribe(
  74. self, topics: Optional[List[str]] = None, pattern: Optional[str] = None, listener: Optional["ConsumerRebalanceListener"] = None
  75. ) -> None:
  76. ...
  77. async def start(self) -> None:
  78. ...
  79. async def stop(self) -> None:
  80. ...
  81. async def commit(self, offsets: Optional[Dict[TopicPartition, int]] = None) -> None:
  82. ...
  83. def __aiter__(self) -> AsyncIterator[ConsumerRecord]:
  84. ...
  85. async def __anext__(self) -> ConsumerRecord:
  86. ...
  87. async def position(self, tp: TopicPartition) -> int:
  88. ...
  89. async def seek(self, tp: TopicPartition, offset: int) -> None:
  90. ...
  91. async def seek_to_beginning(self, tp: TopicPartition) -> None:
  92. ...
  93. def assignment(self) -> Set[TopicPartition]:
  94. ...
  95. async def getmany(
  96. self, *partitions: TopicPartition, timeout_ms: int = 0, max_records: int = None
  97. ) -> Dict[TopicPartition, List[ConsumerRecord]]:
  98. ...
  99. class ConsumerRebalanceListener:
  100. async def on_partitions_revoked(self, revoked: List[TopicPartition]) -> None:
  101. ...
  102. async def on_partitions_assigned(self, assigned: List[TopicPartition]) -> None:
  103. ...
  104. OffsetAndMetadata = namedtuple(
  105. "OffsetAndMetadata",
  106. # TODO add leaderEpoch: OffsetAndMetadata(offset, leaderEpoch, metadata)
  107. ["offset", "metadata"],
  108. )