Skip to content

RPC over RMQ#

Blocking Request#

FastStream provides you with the ability to send a blocking RPC request over RabbitMQ in a very simple way.

It uses the Direct Reply-To RabbitMQ feature, so you don't need to create any queues to consume a response.

Just send a message like a regular one and get a response synchronously.

It is very close to common requests syntax:

from faststream.rabbit import RabbitMessage

msg: RabbitMessage = await broker.request(
    "Hi!",
    queue="test",
)

Reply-To#

Also, if you want to create a permanent request-reply data flow, probably, you should create a permanent queue to consume responses.

So, if you have such one, you can specify it with the reply_to argument. This way, FastStream will send a response to this queue automatically.

@broker.subscriber("response-queue")
async def consume_responses(msg):
    ...

await broker.publish(
    "Hi!",
    queue="test",
    reply_to="response-queue",
)