请求/回复 (RPC) 通过 RabbitMQ 启用了使用消息的同步风格的请求-响应通信——客户端发送请求,并通过回复队列接收响应,使用关联 ID 来匹配响应与请求。这是服务间调用的有用模式。
RabbitMQ 中的 RPC 如何工作
RPC pattern over messaging:
1. CLIENT sends a REQUEST message, including:
→ a REPLY-TO queue (where the response should go)
→ a CORRELATION ID (unique ID to match the response to this request)
2. SERVER (consumer) processes the request and sends a RESPONSE to the reply-to queue,
including the same CORRELATION ID
3. CLIENT receives the response from its reply queue, matches it by CORRELATION ID →
pairs the response with the original request
→ request-response over async messaging
