Currently I’m in the process of designing the messaging system for my application (which uses AMQP on the backend via RabbitMQ). There are going to be multiple instances where a method can get data from multiple sources at the same time (ie. doesn’t have to be sequential queries).
Originally, I was going to use the ThreadPool and QueueUserWorkItem for each different request in the method, and then join them up somehow. This may be problematic, because several different components of the application can do this at once, and each component could have a large number of parallel requests which would starve the ThreadPool.
Is there a more efficient/effective way of doing this?
It’s ok to stress the threadpool. You can throw a bunch of workitems on it – hundreds, thousands – and just let ‘er rip. Not sure what you mean by “starve”. Unless there is a set of work items that ought to be prioritized differently, you probably don’t need to worry about starvation.
If you use QUWI, it’s up to you to figure out how to merge the parallelized results back into one single result.
Sounds to me like you are doing a map/reduce approach. Here’s a quick map function that uses QUWI, and an example of how to use it.
Example of use: