Skip to content

Commit

Permalink
feat: re-using broker instance!
Browse files Browse the repository at this point in the history
  • Loading branch information
amindadgar committed Oct 9, 2024
1 parent 28b7506 commit 4c8c0b9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions routers/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
rabbitmq_creds = load_rabbitmq_credentials()

router = RabbitRouter(rabbitmq_creds["url"])
broker = RabbitBroker(url=rabbitmq_creds["url"])


class Payload(BaseModel):
Expand Down Expand Up @@ -49,10 +50,9 @@ async def ask(payload: Payload, logger: Logger):
date=str(datetime.now()),
content=response_payload.model_dump(),
)
async with RabbitBroker(url=rabbitmq_creds["url"]) as broker:
await broker.publish(
message=result, queue=payload.content.route.destination.queue
)
await broker.publish(
message=result, queue=payload.content.route.destination.queue
)
except Exception as e:
logger.exception(f"Errors While processing job! {e}")
else:
Expand Down

0 comments on commit 4c8c0b9

Please sign in to comment.