correlationId and temporary queues in RPC model - AMQP

家住魔仙堡 提交于 2019-12-03 08:37:26

Correct, temporary queues are unique to the client making the RPC request. We could create the RPC client to have a unique queue for each unique request it makes, but that would be inefficient - see the first paragraph of CorrelationId here:

In the method presented above we suggest creating a callback queue for every RPC request. That's pretty inefficient, but fortunately there is a better way - let's create a single callback queue per client.

So a better way is to have one queue which the RPC client gets response back on and uses the correlationId to match the request that the RPC client makes to the result that the RPC server sends back.

...having received a response in that queue it's not clear to which request the response belongs. That's when the correlation_id property is used. We're going to set it to a unique value for every request. Later, when we receive a message in the callback queue we'll look at this property, and based on that we'll be able to match a response with a request. If we see an unknown correlation_id value, we may safely discard the message - it doesn't belong to our requests.

So referencing the Summary section of the RPC tutorial:

  • when a client starts it creates an exclusive and unique queue
  • when it sends an RPC request it sets the reply_to which is the queue name (so the server knows which queue to send a response to) and also sets a correlationId which is a unique val for each RPC request
  • the request is sent to the RPC queue
  • the RPC worker (or server) receives the request processes it then using the reply_to value sends the response back to the client, it also sets the correlationId
  • the RPC client waits for a response and when it receives one uses the correlationId to MATCH the response with the request
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!