Publish a messages from the method using RabbitRouter #1310
Answered
by
Lancetnik
YanNezamutdinov
asked this question in
Q&A
-
Tell me, can I use RabbitRouter to bypass the data array and publish messages to different queues? For example, as in the code below main.py broker = RabbitBroker("amqp://guest:guest@localhost:5672/")
app = FastStream(broker)
broker.include_router(router_update_data)
async def main():
await app.run()
if __name__ == "__main__":
asyncio.run(main()) update_data.py from faststream.rabbit import RabbitRouter
router_update_data = RabbitRouter()
@router_update_data.subscriber(queue=RabbitQueue("test"),
exchange=RabbitExchange("update_data.direct"))
async def form_data():
for name, data in data_fron_db:
await router_update_data.publish(queue=RabbitQueue(name),
exchange=RabbitExchange("management.direct"),
message=data) |
Beta Was this translation helpful? Give feedback.
Answered by
Lancetnik
Mar 18, 2024
Replies: 1 comment
-
Nope. Router is just a container for methods paramateres storing and pass them into broker lately. In your case you can get broker from Context from faststream.rabbit import RabbitRouter
from faststrea.rabbit.annotations import RabbitBroker
router_update_data = RabbitRouter()
@router_update_data.subscriber(queue=RabbitQueue("test"),
exchange=RabbitExchange("update_data.direct"))
async def form_data(broker: RabbitBroker):
for name, data in data_fron_db:
await broker.publish(queue=RabbitQueue(name),
exchange=RabbitExchange("management.direct"),
message=data) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
YanNezamutdinov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nope. Router is just a container for methods paramateres storing and pass them into broker lately. In your case you can get broker from Context