-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make the kafka topic configurable
- Loading branch information
Showing
9 changed files
with
131 additions
and
103 deletions.
There are no files selected for viewing
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions
25
e2e_tests/message_queues/message_queue_kafka/docker-compose.yml
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,25 @@ | ||
services: | ||
kafka: | ||
image: apache/kafka:3.7.1 | ||
ports: | ||
- "9092:9092" | ||
environment: | ||
KAFKA_NODE_ID: 1 | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT" | ||
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT_HOST://localhost:9092,PLAINTEXT://kafka:19092" | ||
KAFKA_PROCESS_ROLES: "broker,controller" | ||
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka:29093" | ||
KAFKA_LISTENERS: "CONTROLLER://:29093,PLAINTEXT_HOST://:9092,PLAINTEXT://:19092" | ||
KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT" | ||
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER" | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 | ||
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | ||
KAFKA_LOG_DIRS: "/tmp/kraft-combined-logs" | ||
healthcheck: | ||
test: nc -z localhost 9092 || exit -1 | ||
start_period: 15s | ||
interval: 30s | ||
timeout: 10s | ||
retries: 5 |
50 changes: 50 additions & 0 deletions
50
e2e_tests/message_queues/message_queue_kafka/test_message_queue.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,50 @@ | ||
import asyncio | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from llama_deploy.message_consumers.callable import CallableMessageConsumer | ||
from llama_deploy.message_queues import KafkaMessageQueue, KafkaMessageQueueConfig | ||
from llama_deploy.messages import QueueMessage | ||
|
||
|
||
@pytest.fixture | ||
def kafka_service(): | ||
cwd = Path(__file__).resolve().parent | ||
proc = subprocess.Popen(["docker-compose", "up", "-d", "--wait"], cwd=cwd) | ||
proc.communicate() | ||
yield | ||
subprocess.Popen(["docker-compose", "down"], cwd=cwd) | ||
|
||
|
||
@pytest.fixture | ||
def mq(kafka_service): | ||
return KafkaMessageQueue(KafkaMessageQueueConfig(topic_name="test")) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_roundtrip(mq): | ||
received_messages = [] | ||
|
||
# register a consumer | ||
def message_handler(message: QueueMessage) -> None: | ||
received_messages.append(message) | ||
|
||
test_consumer = CallableMessageConsumer( | ||
message_type="test", handler=message_handler | ||
) | ||
start_consuming_callable = await mq.register_consumer(test_consumer) | ||
|
||
# produce a message | ||
test_message = QueueMessage(type="test", data={"message": "this is a test"}) | ||
|
||
# await asyncio.gather(start_consuming_callable(), mq.publish(test_message)) | ||
await mq.publish(test_message) | ||
t = asyncio.create_task(start_consuming_callable()) | ||
await asyncio.sleep(0.5) | ||
# at this point message should've been arrived | ||
t.cancel() | ||
|
||
assert len(received_messages) == 1 | ||
assert test_message in received_messages |
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
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.