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

Roberto Pagliari roberto at canary.is
Fri Jan 17 04:50:00 GMT 2014


Hi Alan,
a break statement should exit the while loop isnt it? I expected to see a
'continue', instead...

Roberto



On Thu, Jan 16, 2014 at 9:44 PM, Alan Antonuk <alan.antonuk at gmail.com>wrote:

>
>
>
> 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
>
> _______________________________________________
> 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/20140116/6d105f9c/attachment.html>


More information about the rabbitmq-discuss mailing list