Skip to content

Commit

Permalink
make kafka topic an env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip117 committed Jul 9, 2024
1 parent a59060c commit 3e789b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
## pfdcm
app = FastAPI(
title='consumer',
version='0.0.1',
version='0.1.0',
contact={"name": "FNNDSC", "email": "[email protected]"},
openapi_tags=[],
description=description
Expand All @@ -32,6 +32,7 @@
allow_headers=["*"],
)
loop = asyncio.get_event_loop()
kafka_topic = os.getenv('KAFKA_TOPIC')

async def consume():
consumer = None
Expand All @@ -41,7 +42,7 @@ async def consume():
except Exception as ex:
print(f"{ex}. Retrying in 10 seconds")
sleep(10)
consumer = AIOKafkaConsumer("test", bootstrap_servers=f"{os.getenv('KAFKA_URL')},{os.getenv('KAFKA_URL')}",
consumer = AIOKafkaConsumer(kafka_topic, bootstrap_servers=f"{os.getenv('KAFKA_URL')},{os.getenv('KAFKA_URL')}",
loop=loop)

await consumer.start()
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
command: uvicorn app.main:app --reload --workers 1 --host 0.0.0.0 --port 2020
environment:
KAFKA_URL: "127.0.0.1:9092"
KAFKA_TOPIC: "test"
volumes:
- ./:/app/

0 comments on commit 3e789b2

Please sign in to comment.