enhance: RabbitMQ config
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
from pydantic import Field
|
|
||||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
|
||||||
@@ -7,6 +6,14 @@ class Config(BaseSettings):
|
|||||||
env_file=".env", env_ignore_empty=True, extra="ignore"
|
env_file=".env", env_ignore_empty=True, extra="ignore"
|
||||||
)
|
)
|
||||||
|
|
||||||
RABBITMQ_URL: str
|
RABBITMQ_HOST: str
|
||||||
|
RABBITMQ_PORT: int
|
||||||
|
RABBITMQ_USER: str
|
||||||
|
RABBITMQ_PASSWORD: str
|
||||||
|
|
||||||
|
@property
|
||||||
|
def RABBITMQ_URI(self) -> str:
|
||||||
|
return f"amqp://{self.RABBITMQ_USER}:{self.RABBITMQ_PASSWORD}@{self.RABBITMQ_HOST}:{self.RABBITMQ_PORT}/"
|
||||||
|
|
||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
from aiogram.types import Update
|
from aiogram.types import Update
|
||||||
from typing import Literal
|
|
||||||
from fastapi import Depends, Request, Response
|
from fastapi import Depends, Request, Response
|
||||||
from fastapi.datastructures import State
|
from fastapi.datastructures import State
|
||||||
from faststream.rabbit.fastapi import ContextRepo
|
from faststream.rabbit.fastapi import ContextRepo
|
||||||
@@ -16,6 +15,7 @@ from .utils import override_route
|
|||||||
|
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def telegram_webhook(
|
async def telegram_webhook(
|
||||||
request: Request,
|
request: Request,
|
||||||
):
|
):
|
||||||
@@ -52,11 +52,11 @@ class FaststreamPlugin:
|
|||||||
self.broker_router = None
|
self.broker_router = None
|
||||||
|
|
||||||
def register(self, app: QuickBot) -> None:
|
def register(self, app: QuickBot) -> None:
|
||||||
self.broker_router = RabbitRouter(
|
self.broker_router = RabbitRouter(url=config.RABBITMQ_URI)
|
||||||
url=config.RABBITMQ_URL
|
|
||||||
)
|
|
||||||
|
|
||||||
@self.broker_router.subscriber(queue=f"{app.config.STACK_NAME}.telegram_updates", no_reply=True)
|
@self.broker_router.subscriber(
|
||||||
|
queue=f"{app.config.STACK_NAME}.telegram_updates", no_reply=True
|
||||||
|
)
|
||||||
async def telegram_updates_handler(
|
async def telegram_updates_handler(
|
||||||
message: dict,
|
message: dict,
|
||||||
db_session: Annotated[AsyncSession, Depends(get_db)],
|
db_session: Annotated[AsyncSession, Depends(get_db)],
|
||||||
@@ -83,4 +83,3 @@ class FaststreamPlugin:
|
|||||||
app.include_router(self.broker_router)
|
app.include_router(self.broker_router)
|
||||||
|
|
||||||
override_route(app, name="telegram_webhook", new_endpoint=telegram_webhook)
|
override_route(app, name="telegram_webhook", new_endpoint=telegram_webhook)
|
||||||
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
from fastapi import FastAPI, APIRouter
|
from fastapi import FastAPI
|
||||||
from fastapi.routing import APIRoute
|
from fastapi.routing import APIRoute
|
||||||
|
|
||||||
|
|
||||||
def override_route(
|
def override_route(
|
||||||
app: FastAPI,
|
app: FastAPI,
|
||||||
*,
|
*,
|
||||||
|
|||||||
Reference in New Issue
Block a user