[rabbitmq-discuss] [RabbitMQ-c] Question about amqp_listen example

Alan Antonuk alan.antonuk at gmail.com
Fri Jan 17 02:44:16 GMT 2014


On Thu, Jan 16, 2014 at 4:51 PM, Roberto Pagliari <roberto at canary.is> wrote:

> I have a couple of questions about the overall functioning of Rabbitmq-c.
>
> From amqp_listen.c I see the following code:
>
>   {
>     while (1) {
>       amqp_rpc_reply_t res;
>
>       amqp_envelope_t envelope;
>
>       amqp_maybe_release_buffers(conn);
>
>       res = amqp_consume_message(conn, &envelope, NULL, 0);
>
>       if (AMQP_RESPONSE_NORMAL != res.reply_type) {
>         break;
>       }
>
>       printf("Delivery %u, exchange %.*s routingkey %.*s\n",
>              (unsigned) envelope.delivery_tag,
>              (int) envelope.exchange.len, (char *) envelope.exchange.bytes,
>              (int) envelope.routing_key.len, (char *) envelope.routing_key.bytes);
>
>       if (envelope.message.properties._flags & AMQP_BASIC_CONTENT_TYPE_FLAG) {
>         printf("Content-type: %.*s\n",
>                (int) envelope.message.properties.content_type.len,
>                (char *) envelope.message.properties.content_type.bytes);
>       }
>
>       amqp_destroy_envelope(&envelope);
>     }
>   }
>
>
> First off, the output I'm getting when sending the string "Hello world" is
> $ ./amqp_listen localhost 5672 amq.direct test
> Delivery 1, exchange amq.direct routingkey test
> Content-type: text/plain
>
>
> 1) Is that what the output should be like? I though it was supposed to
> print out the string sent with amqp_sendstring on the other side.
>
The output is correct, it does not print out the body of the message.

> 2) In the code above, it looks like the printf is performed every time,
> regardless of weather a message has been received or not. However, only
> when a message is actually received, the printf will execute. Could someone
> explain me why this is the case?
>
The if (AMQP_RESPONSE_NORMAL != res.reply_type) break; statement will break
out of the loop if the message isn't received.

-Alan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20140116/e3cefc57/attachment.html>


More information about the rabbitmq-discuss mailing list