-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1691 from langchain-ai/nc/11sep/kafka-sync
kafka: Implement sync orchestrator and executor classes
- Loading branch information
Showing
14 changed files
with
1,628 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 1 addition & 8 deletions
9
libs/scheduler-kafka/langgraph/scheduler/kafka/default_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
libs/scheduler-kafka/langgraph/scheduler/kafka/default_sync.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import concurrent.futures | ||
from typing import Optional, Sequence | ||
|
||
from kafka import KafkaConsumer, KafkaProducer | ||
from langgraph.scheduler.kafka.types import ConsumerRecord, TopicPartition | ||
|
||
|
||
class DefaultConsumer(KafkaConsumer): | ||
def getmany( | ||
self, timeout_ms: int, max_records: int | ||
) -> dict[TopicPartition, Sequence[ConsumerRecord]]: | ||
return self.poll(timeout_ms=timeout_ms, max_records=max_records) | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
self.close() | ||
|
||
|
||
class DefaultProducer(KafkaProducer): | ||
def send( | ||
self, | ||
topic: str, | ||
*, | ||
key: Optional[bytes] = None, | ||
value: Optional[bytes] = None, | ||
) -> concurrent.futures.Future: | ||
fut = concurrent.futures.Future() | ||
kfut = super().send(topic, key=key, value=value) | ||
kfut.add_callback(fut.set_result) | ||
kfut.add_errback(fut.set_exception) | ||
return fut | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
self.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.