RabbitMQ RPC close response queue on final message

I am planning on implementing an RPC pattern with RabbitMQ. A client will send a message to request a snapshot of data from a server. The server will send many messages containing the snapshot data back to the client over a response queue. When the last message has been received, the client should destroy the response queue.

I can implement this pattern manually by placing some field in the message or message headers, but is there a best practice way of implementing this, perhaps a designated header field for signalling the last message?


When the last message has been received, the client should destroy the response queue.

my first reaction, is "why?"

it's common practice to have a client app open a "reply" queue when the client connects, and leave it open for as long as the client is connected, re-using it for all replies. using auto-delete, as pinepain suggested, would delete the queue when the client disconnects.

I can implement this pattern manually by placing some field in the message or message headers, but is there a best practice way of implementing this, perhaps a designated header field for signalling the last message?

There's no real best practice here, other than what you've suggested. There isn't a specific field in a RabbitMQ message for this, though.

You can add any header you wish to the message, and use that header as the flag to say the replies for this request are complete. Alternatively, you can just use the message body to contain the status.

Either of these (and probably many more options) will work just fine.

链接地址: http://www.djcxy.com/p/61228.html

上一篇: 我如何使用RabbitMq进行异步RPC调用

下一篇: 最终消息中的RabbitMQ RPC关闭响应队列