[rabbitmq-discuss] Channel thread safety in Java Client
0x6e6562 at gmail.com
Sat Jul 4 09:33:56 BST 2009
On Fri, Jul 3, 2009 at 9:34 PM, tsuraan<tsuraan at gmail.com> wrote:
> In the Java client guide, it states that channels should not be used
> by more than one thread simultaneously. How can I guarantee this when
> I have a consumer on a channel? I'd like to have a consumer that puts
> messages into a local java BlockingQueue, and then once the messages
> are handled by other threads, they are acked on the channel that they
> came from. I can easily ensure that none of my acks coincide with
> each other, but how can I ensure that the Connection thread isn't
> using the Channel while I'm trying to do an ack?
The race condition can occur within a single channel is when message
sending gets interleaved and hence sends jumbled frames to the broker.
The connection thread OTOH is not using the channel to transmit
messages, rather, it is the channel that is using the connection to
transmit messages, so I don't think you'll run into an issue if you
are, as I assume, maintaining a mutex around the shared channel
BTW (I know that app might not permit this), but have you considered
using a channel per consumer?
More information about the rabbitmq-discuss