[rabbitmq-discuss] Rabbitmq-c Help

David Wragg david at rabbitmq.com
Wed Sep 22 22:23:54 BST 2010


Hi Pieter,

Pieter de Zwart <pdezwart at rubiconproject.com> writes:
> You diagnosis was absolutely correct. I wrongly assumed that the Fedora
> repository contained the latest RabbitMQ server version, which it did not. I
> am, however, at another impass. I have tweaked my code a little to work with
> 0-9-1, but I have run into a segfault in the rabbitmq-c client, which, lets
> face it, is probably my doing.
> The segfault occurs when I try to consume, with the following code:
>
>     amqp_basic_consume_t s;
>     s.ticket                = 0;
>     s.queue.len                 = ctx->name_len;
>     s.queue.bytes            = ctx->name;
>     s.consumer_tag.len        = 0;
>     s.consumer_tag.bytes    = NULL;
>     s.no_local                = (AMQP_NOLOCAL & parms) ? 1 : 0;
>     s.no_ack                = (AMQP_NOACK & parms) ? 1 : 0;
>     s.exclusive                = (AMQP_EXCLUSIVE & parms) ? 1 : 0;
>     s.nowait                = 0;
>
>     amqp_method_number_t method_ok = AMQP_BASIC_CONSUME_OK_METHOD;
>     res = (amqp_rpc_reply_t)amqp_simple_rpc(
>         cnn->conn,
>         AMQP_CHANNEL,
>         AMQP_BASIC_CONSUME_METHOD,
>         &method_ok,
>         &s
>     ); 

There are a couple of issues here.

The first, and the one that's leading to your segfault and backtrace
gave, is that you are not setting the "arguments" field of the
amqp_basic_consume_t struct.  Setting it to NULL would be fine.

With that fixed, I think you will run into a problem with
method_ok. That argument is supposed to be a zero-terminated array of
acceptable reply method ids.  So it should be something like:

    amqp_method_number_t methods_ok[] = { AMQP_BASIC_CONSUME_OK_METHOD, 0 };

But really, I think you should be calling amqp_basic_consume, which will
take case of both those things.  Is there a reason you're not using it?

> [...]
>
> Thoughts on what I am doing wrong? Is there a spec somewhere I can
> use? =)

I'm afraid not.  The C client could do with some documentation work.

David

-- 
David Wragg
Staff Engineer, RabbitMQ
SpringSource, a division of VMware


More information about the rabbitmq-discuss mailing list