[rabbitmq-discuss] Java client threading design
Tim Watson
tim at rabbitmq.com
Wed Sep 5 12:50:40 BST 2012
On 28 Aug 2012, at 18:03, Kashif Shaikh wrote:
> I'm just trying to understand the threading design:
>
> - When a consumer is started for any queue on a particular channel, a thread is selected from the default executor service?
Well, you can supply your own, as per http://www.rabbitmq.com/api-guide.html#advanced-connection
> - Does a channel create a thread for itself?
>
Yes, the Channel maintains a single dispatch thread.
> - I have a threadpool for my application that processes requests and does consumes (amongst other tasks) - I don't want my threadpool servicing the consume callbacks. So can I keep a single global channel, and just call basicConsume and register callbacks that will be executed on the default executor?
The problem with a 'global' channel like this is that multiple consumers on the channel will block (because the Channel uses a single dispatch thread, as I mentioned earlier). One consumer per channel (and therefore one Channel per thread) will eliminate this problem.
> Or should I create a channel for each thread in my threadpool, and then use channel.basicConsume()?
>
Well this just depends on why you 'don't want your threadpool servicing the consume callbacks'. The threadpool that is used for consumer callbacks is either a default (internally created) one or you can supply your own, and it doesn't have to be the main application thread pool if you don't want it to be. I'd suggest reading through http://www.rabbitmq.com/api-guide.html#consuming in detail for a better understanding of this.
> - what happens if connection breaks - do I have to re-consume again?
>
Yes you do.
More information about the rabbitmq-discuss
mailing list