rabbitmq implemented and tested
This commit is contained in:
18
ServicesTask/app/services/mongo/Dockerfile
Normal file
18
ServicesTask/app/services/mongo/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
FROM python:3.12-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
ENV PYTHONPATH=/app
|
||||
|
||||
WORKDIR /
|
||||
|
||||
COPY app/services/mongo/pyproject.toml ./
|
||||
COPY app/services/mongo/README.md ./
|
||||
|
||||
COPY app/core ./app/core
|
||||
COPY app/services/common/ ./app/services/common/
|
||||
COPY app/services/mongo/ ./app/services/mongo/
|
||||
|
||||
RUN pip install --upgrade pip && pip install --no-cache-dir .
|
||||
RUN mkdir -p /app/data
|
||||
|
||||
CMD ["python", "-m", "app.services.mongo.main"]
|
||||
0
ServicesTask/app/services/mongo/README.md
Normal file
0
ServicesTask/app/services/mongo/README.md
Normal file
0
ServicesTask/app/services/mongo/__init__.py
Normal file
0
ServicesTask/app/services/mongo/__init__.py
Normal file
40
ServicesTask/app/services/mongo/main.py
Normal file
40
ServicesTask/app/services/mongo/main.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
import uuid
|
||||
import asyncio
|
||||
|
||||
from app.services.common.service_base_async import ServiceBaseAsync
|
||||
|
||||
|
||||
PRODUCE_BURST = int(os.getenv("PRODUCE_BURST", "10"))
|
||||
PRODUCE_ONCE = os.getenv("PRODUCE_ONCE", "true").lower() == "true"
|
||||
EVENT_TYPE = os.getenv("EVENT_TYPE", "db-mongo")
|
||||
PROCESS_SEC = 10
|
||||
|
||||
|
||||
async def produce(svc: ServiceBaseAsync):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print(f"Produced From Mongo Producer: {len([1,2])} events to '{svc.produce_key}'")
|
||||
|
||||
|
||||
async def handle_db_publish(svc: ServiceBaseAsync, job):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
await svc.ack_current()
|
||||
print("Mongo Consumer from db:", job["task_id"])
|
||||
|
||||
|
||||
async def handle_mail_publish(svc: ServiceBaseAsync, job):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
await svc.ack_current()
|
||||
print("Mongo Consumer from mail:", job["task_id"])
|
||||
|
||||
|
||||
async def consume_default(svc, job):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print("Mongo Consumer default:", job["task_id"])
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"database.service.publish": handle_db_publish, "mail.service.publish": handle_mail_publish})
|
||||
asyncio.run(svc.run())
|
||||
37
ServicesTask/app/services/mongo/pyproject.toml
Normal file
37
ServicesTask/app/services/mongo/pyproject.toml
Normal file
@@ -0,0 +1,37 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "dual-queue-services"
|
||||
version = "0.1.0"
|
||||
description = "Async dual queue system with Redis Streams and SQLite persistence"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
authors = [
|
||||
{ name = "Berkay Karatay", email = "karatay.berkay@gmail.com" }
|
||||
]
|
||||
|
||||
dependencies = [
|
||||
"aio-pika>=9.4.1",
|
||||
"prometheus-client>=0.20.0",
|
||||
"uvloop>=0.19.0"
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"pytest>=7.4",
|
||||
"black>=23.0",
|
||||
"isort>=5.12"
|
||||
]
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ["py311"]
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["app"]
|
||||
include = ["app*"]
|
||||
16
ServicesTask/app/services/mongo/queue_service_async.py
Normal file
16
ServicesTask/app/services/mongo/queue_service_async.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import asyncio
|
||||
|
||||
from services.service_base_async import ServiceBaseAsync
|
||||
|
||||
|
||||
async def produce(service: ServiceBaseAsync):
|
||||
fake_jobs = [{"action": "cleanup", "target": "old-tasks"}]
|
||||
for job in fake_jobs:
|
||||
await service.enqueue(job, "queue-maintenance")
|
||||
|
||||
async def consume(service: ServiceBaseAsync, job: dict):
|
||||
print(f"[QUEUE CONTROL] İşleme alındı: {job}")
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(ServiceBaseAsync(produce, consume).run())
|
||||
Reference in New Issue
Block a user