Skip to content

Commit d3c7584

Browse files
authored
Merge pull request #6 from Ifechukwu001/feat/rabbitmq
Implemented the RabbitMQ service broker
2 parents fa362a9 + cb1ece4 commit d3c7584

File tree

8 files changed

+449
-80
lines changed

8 files changed

+449
-80
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ JWT_ISSUER=xxx
3030
OTP_LIFETIME=10
3131

3232
API_GATEWAY_PUBLIC_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
33-
API_KEY_EXPIRES_AT=2
33+
API_KEY_EXPIRES_AT=2
34+
35+
RABBITMQ_HOST=localhost

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ The Swagger documentation for the application is hosted on [Render](https://df-u
4444
- Run the server locally on port 8000
4545

4646
```bash
47-
uv run manage.py runserver 8000
47+
uv run uvicorn src.config.asgi:application --reload --port 8000
4848
```

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ dependencies = [
1919
"pydantic[email]>=2.10.6",
2020
"django-ninja>=1.3.0",
2121
"pyjwt>=2.10.1",
22-
"typing>=3.10.0.0",
22+
"faststream[rabbit]>=0.5.39",
23+
"starlette>=0.46.2",
24+
"uvicorn>=0.34.2",
2325
]
2426

2527
[dependency-groups]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/api/services/external/__init__.py

Whitespace-only changes.

src/config/asgi.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@
1010
import os
1111

1212
from django.core.asgi import get_asgi_application
13+
from faststream.rabbit import RabbitBroker
14+
from starlette.routing import Mount
15+
from starlette.applications import Starlette
16+
17+
from src.env import rabbitmq_config
18+
19+
broker = RabbitBroker(host=rabbitmq_config["host"])
20+
1321

1422
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.config.settings")
1523

16-
application = get_asgi_application()
24+
application = Starlette(
25+
routes=[Mount("/", get_asgi_application())], # type: ignore
26+
on_startup=[broker.start],
27+
on_shutdown=[broker.close],
28+
)
29+
30+
31+
from src.api.services.external import RabbitMQRoutes as RabbitMQRoutes # noqa: E402

src/env.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class OTP(TypedDict):
5050
lifetime: int
5151

5252

53+
class RabbitMQ(TypedDict):
54+
host: str
55+
56+
5357
env = Env()
5458

5559
app: App = {
@@ -105,4 +109,17 @@ class OTP(TypedDict):
105109

106110
otp: OTP = {"lifetime": get_env_int("OTP_LIFETIME")}
107111

108-
__all__ = ["api_gateway", "app", "cache", "db", "env", "jwt_config", "log", "otp"]
112+
rabbitmq_config: RabbitMQ = {"host": get_env_str("RABBITMQ_HOST")}
113+
114+
115+
__all__ = [
116+
"api_gateway",
117+
"app",
118+
"cache",
119+
"db",
120+
"env",
121+
"jwt_config",
122+
"log",
123+
"otp",
124+
"rabbitmq_config",
125+
]

uv.lock

Lines changed: 407 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)