[rabbitmq-discuss] Multithreading and rabbitmq-c

Alan Antonuk alan.antonuk at gmail.com
Thu Mar 15 14:43:02 GMT 2012


Inlined:

-Alan

On Thu, Mar 15, 2012 at 9:57 AM, Artsiom <u2.storm at gmail.com> wrote:

>  I some questions concerning multithreading and using multiple channels
> within single connection.
>
> Is structure amqp_connection_state_t is thread-safe?
> Can I share connection between threads and at the same time
> use separate channel for each thread in producer app? and in consumer app?
>

The amqp_connection_state_t object is not synchronized. In order to use it
from multiple threads you would have to synchronize its use across threads
(provide some external mutual exclusion when calling any amqp_* function
that uses a common amqp_connection_state_t).


> The second part of the question(about consumer) is needed to be explained.
> When I looked at API, I didn't find any difficulties to use many channels
> within single connection
> in producer app, because each method (declare queue\exchange, bind,
> publish & etc) has
> "channel" parameter.
>
> But in consumer app, where it is needed to receive messages (or frames as
> shown in example .c-files),
> we have to call wait_for_single_frame method, which is lack of "channel"
> method.
> Could you give an advice how to organize "multichannel" message fetch from
> one queue?
>

The API for consuming messages is pretty low-level at this point.  In order
to consume from multiple channels you need to read messages from all the
channels using amqp_simple_wait_frame, then provide your own logic to
handle messages from different channels appropriately.

>
>
> *OR*
> It is better to use separate connection for each thread and have no
> problems? :)
>
> That would the the easiest way to get started.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120315/9d238a39/attachment.htm>


More information about the rabbitmq-discuss mailing list