[rabbitmq-discuss] Multithreading and rabbitmq-c

Alan Antonuk alan.antonuk at gmail.com
Fri Feb 10 20:58:30 GMT 2012


Responses inlined below:

-Alan

On Fri, Feb 10, 2012 at 2:00 PM, Arun Chandrasekaran <visionofarun at gmail.com
> wrote:

> Hi all,
>
> With rabbitmq-c, it is possible to bind on different channels from
> different threads?
>
> Basically, I'm not sharing any of these between the threads:
> amqp_connection_state_t, socket, channel.
>

You have interpreted the documentation correctly:

amqp_connection_state_t, its socket, and all associated amqp_channel_t's
must not be shared between threads.  Its ok to have separate instances of
these objects used in different threads.


> Here is the "examples/amqp_consumer.c" sample code modified for 2 threads:
> http://codepad.org/zPa91lbr. I have also attached the code for your
> reference.
>
> I get this error from the second thread :
>
> "Declaring queue: server connection error 504, message: CHANNEL_ERROR -
> expected 'channel.open'"
>
Your problem is on line 156:
amqp_channel_open(conn, 1); /* opens channel 1 */

You then try to use channel stored in the variable chan on line 160:
... = amqp_queue_declare(conn, chan /* may not be channel 1 */ ...);

Try changing 156 to open channel stored in chan.

Also note that channels are on a per-connection basis, so it is ok to have
two different connections with the same channel identifiers.


> The README clearly states that it is valid to have different connections,
> sockets and channels per thread (last section):
> http://hg.rabbitmq.com/rabbitmq-c/file/fb6fca832fd2/README
>

Just an FYI: the canonical sources for the rabbitmq-c library have moved to
a new location:
https://github.com/alanxz/rabbitmq-c


>
> Can someone give me an insight into where I am going wrong or if it is a
> limitation with rabbitmq-c?
>
> Cheers,
> Arun
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120210/c6711c10/attachment.htm>


More information about the rabbitmq-discuss mailing list