[rabbitmq-discuss] Multithreading and rabbitmq-c

Valentin BERNARD vbernard42 at gmail.com
Thu Mar 15 14:56:59 GMT 2012


Hi,

With regard to thread-safety, I personally ended up manually
synchronizing every method using a given connection, so that any
channel can be used from any thread. There may be a more subtle
answer.

Concerning multichannel fetching, here is (very schematically) what I
do:

fetch_channel(channel_no) {
   if deliveries[channel_no].size() > 0
      return deliveries[channel_no].dequeue()
   else
      return receive_delivery(channel_no)

receive_delivery(channel_no)
   do {
      receive some_delivery
      if some_delivery.channel_no == channel_no
         return some_delivery
      else
         deliveries[channel_no].enqueue(some_delivery)
   } continue until we get a delivery for this channel or reach some
sort of timeout.

Cheers.

Valentin.

On 15 mar, 14:57, Artsiom <u2.st... 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 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?
>
> *OR*
> It is better to use separate connection for each thread and have no
> problems? :)
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-disc... at lists.rabbitmq.comhttps://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list