Reputation: 5190
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?
Upvotes: 3
Views: 606
Reputation: 45252
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.
Upvotes: 4
Reputation: 62439
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.
Upvotes: 1