使用 msmq 队列对服务进行负载平衡?
是否可以使用 MSMQ 队列来负载平衡请求?如果我有 1-n 个客户端向 WCF 服务发送请求,然后将每个请求排入队列,并且在后台有 1-n 个服务器,每个服务器在下一个可用请求可用时抓取它们,我会假设这有效地实现了负载平衡。但是,我该如何得到回复呢?我意识到我可以在 WCF 服务中订阅“完整”事件,但是当我只关心一个事件时,我必须解析所有事件。如何使用这种架构实现某种回调机制?
Is it possible to use an MSMQ queue to load-balance requests? If I have clients 1-n send in requests to a WCF service, which then enqueues each request, and have 1-n servers in the background each grabbing the next available request as they become available, I would assume this effectively load-balances.. however, how would I then get the response back? I realize I could subscribe to 'complete' events in my WCF service, but then i have to parse all events when i only care about one.. How could I accomplish a callback mechanism of some sort with this architecture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 MSMQ 发送事件,则不存在“获取响应”的内置概念。
这是一个解决方案:每个客户端都可以有自己的消息队列来监听。当工作人员完成任务后,他们可以将“已完成”消息发送回客户端。
但是服务器如何知道客户端消息队列的地址呢?
一种方法是提供客户端的消息队列地址作为每个函数中的参数。
更好的方法是将此地址作为自定义标头值包含在内。
自定义标头解决方案是更好的方法,原因有两个。首先,这可以通过客户端的配置文件进行配置,从而允许在部署后更改队列详细信息。其次,永远不希望通信“管道”的细节侵入函数调用抽象层,而自定义标头解决方案可以让您避免这种情况。
有关使用自定义标头的示例,请参阅此问题。
If you are using the MSMQ to send events, then there is no inbuilt concept of "getting the response back".
Here's a solution: the clients can each have their own message queue which they listen on. When the workers have completed their tasks they can send a "completed" message back to the client.
But how would the server know the address of the client's message queue?
One approach would be to supply the client's message queue address as a parameter in each function.
A better approach would be to include this address as a custom header value.
The custom header solution is a better approach for two reasons. Firstly, this can be configured via the client's configuration file, allowing the queue details to be changed after deployment. Secondly, it's never desirable for the details of the communication "plumbing" to intrude into the function call abstraction layer, and the custom header solution allows you to avoid this.
See this question for an example of custom headers being used.
您可以让工作人员将回复放入单独的回复队列中。然后只需为每个请求-回复对使用一些唯一的 ID 即可识别正确的回复。
You can have the workers put the replies in a separate reply queue. Then just use some unique id for each request-reply pair to identify the correct reply.