[rabbitmq-discuss] Channel thread-safety

Laurent Vauthrin lvauthrin at gmail.com
Mon Oct 22 20:05:42 BST 2012


I've done some searching but can't seem to answer a couple of questions.
 In the API guide, I saw:

"Channel instances are safe for use by multiple threads. Requests into a
Channel are serialized, with only one thread being able to run a command on
the Channel at a time. Even so, applications should prefer using a Channel
per thread instead of sharing the same Channel across multiple threads."

And in the Javadocs for Channel, I saw:

"While a Channel can be used by multiple threads, it's important to ensure
that only one thread executes a command at once. Concurrent execution of
commands will likely cause an UnexpectedFrameError to be thrown."

Currently, our service shares the same channel across each request thread
and we synchronize the call to 'basicPublish'.  Looking at the basicPublish
code, it looks like the sequence number member variable is not thread safe
but it doesn't affect us since we're not ack'ing our messages.

My questions are:
1. Should we be using a channel per thread considering that we're
synchronizing the basicPublish call anyway?
2. Can we just share one channel across all threads and not synchronize the
call to basicPublish?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20121022/ab4de8ca/attachment.htm>

More information about the rabbitmq-discuss mailing list