Parallel RPC with asyncio.gather
#1173
Answered
by
Lancetnik
PhoenixNazarov
asked this question in
Q&A
-
I'm using RabbitMq. And I start the server with one queue, and then I return “123” for all tasks. When I call async def p():
out = await broker.publish(message, queue, exchange,
expiration=60,
rpc_timeout=100,
rpc=True)
print(out)
async def main():
await asyncio.gather(*[p1(), p1()]) I only receive an answer to one created task, the second one hangs endlessly and does not receive its answer. |
Beta Was this translation helpful? Give feedback.
Answered by
Lancetnik
Jan 30, 2024
Replies: 1 comment 7 replies
-
@PhoenixNazarov, sorry, I can't reproduse your problem My RPC publish example is working correctly import asyncio
from faststream import FastStream, Logger
from faststream.rabbit import RabbitBroker
broker = RabbitBroker()
app = FastStream(broker)
@broker.subscriber("test-q")
async def handler(msg, logger: Logger):
logger.info(msg)
return msg
@app.after_startup
async def t():
result = await asyncio.gather(
broker.publish(1, "test-q", rpc=True),
broker.publish(2, "test-q", rpc=True),
)
assert result == [1, 2] |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@PhoenixNazarov please, do not try to
connect
broker concurantly: it can leads to race condition.The following code should works fine