Is it required to define the exchange and pseudo queue for direct reply-to? #363
-
Hi all Thanks for this great library, we just learned about it as we run into limitations of the While reading the docs, I saw that the
According to the rabbitmq docs:
As I understand it from the docs, no queue is required and the default exchange can be used. Many thanks!! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
The queue you're referring to is for the client issuing the request (for the response to be returned to), not the destination for the request. Without the automatic use of the reply-to queue, if you wanted to get a response back from the Because the library abstracts the reply-to queue, you can simply make a request to an RPC route using a promise with async/await and you'll get the response back automatically over the reply-to queue without doing any extra work |
Beta Was this translation helpful? Give feedback.
-
Hey @WonderPanda Many thanks for you reply! Sorry, I am struggling a bit to understand your answer.
Are you referring to the From the RabbitMQ docs, I had the impression that a request is returned to the
If multiple clients would like to make a request to the same RPC handler, would I need to create multiple handlers with multiple reply-to queues? Or do those need to listen to all the same Thank you! |
Beta Was this translation helpful? Give feedback.
-
No, Once the RPC queue receives and processes the message the question is, how does it send you back a reply? Normally you would have to set up your own queue manually to receive the response on. With direct-reply you don't need to worry about that. The takeaway is that the library abstracts this away from you and there is very little you need to do. Assuming you have an RPC listener configured as above and you want to get a response from it, you just do this: const response = await amqpConnection.request<ExpectedReturnType>({
exchange: 'exchange1',
routingKey: 'rpc',
payload: {
request: 'val',
},
timeout: 10000, // optional timeout for how long the request
// should wait before failing if no response is received
}); There is nothing else you need to do as a requester, all of the direct reply to mechanism is abstracted away for you. Additional InfoYou're not required to give your RPC listener a dedicated queue, but it can be useful depending on your architecture. If you don't, a random one will be auto assigned to it. If your application restarts though there are chances that messages that haven't been processed yet could be lost. |
Beta Was this translation helpful? Give feedback.
No,
rpc-queue
is where the RPC will be listening. It attaches to the exchange and routing key and all of the messages sent will end up in its own queue to be processed. If you want to get a response you need to send a request to to the exchange + routing key where the RPC is listening.Once the RPC queue receives and processes the message the question is, how does it send you back a reply? Normally you would have to set up your own queue manually to receive the response on. With direct-reply you don't need to worry about that.
The takeaway is that the library abstracts this away from you and there is very little you need to do. Assuming you have an RPC listener configured as above and you…