<div dir="ltr">Hi Alan,<div>a break statement should exit the while loop isnt it? I expected to see a 'continue', instead...</div><div><br></div><div>Roberto </div><div><br></div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Thu, Jan 16, 2014 at 9:44 PM, Alan Antonuk <span dir="ltr"><<a href="mailto:alan.antonuk@gmail.com" target="_blank">alan.antonuk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote"><div class="im">On Thu, Jan 16, 2014 at 4:51 PM, Roberto Pagliari <span dir="ltr"><<a href="mailto:roberto@canary.is" target="_blank">roberto@canary.is</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have a couple of questions about the overall functioning of Rabbitmq-c. <div><br></div><div>From amqp_listen.c I see the following code: </div>

<div><br></div><div><pre style="font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);line-height:18px"><div style="padding-left:10px">  <span>{</span></div>

<div style="padding-left:10px">    <span style="font-weight:bold">while</span> <span>(</span><span style="color:rgb(0,153,153)">1</span><span>)</span> <span>{</span></div>
<div style="padding-left:10px">      <span style="color:rgb(68,85,136);font-weight:bold">amqp_rpc_reply_t</span> <span>res</span><span>;</span></div><div style="padding-left:10px">
      <span style="color:rgb(68,85,136);font-weight:bold">amqp_envelope_t</span> <span>envelope</span><span>;</span></div><div style="padding-left:10px"><br>
</div><div style="padding-left:10px">      <span>amqp_maybe_release_buffers</span><span>(</span><span>conn</span><span>);</span></div><div style="padding-left:10px">
<br></div><div style="padding-left:10px">      <span>res</span> <span style="font-weight:bold">=</span> <span>amqp_consume_message</span><span>(</span><span>conn</span><span>,</span> <span style="font-weight:bold">&</span><span>envelope</span><span>,</span> <span style="color:rgb(0,134,179)">NULL</span><span>,</span> <span style="color:rgb(0,153,153)">0</span><span>);</span></div>


<div style="padding-left:10px"><br></div><div style="padding-left:10px">      <span style="font-weight:bold">if</span> <span>(</span><span>AMQP_RESPONSE_NORMAL</span> <span style="font-weight:bold">!=</span> <span>res</span><span>.</span><span>reply_type</span><span>)</span> <span>{</span></div>


<div style="padding-left:10px">        <span style="font-weight:bold">break</span><span>;</span></div><div style="padding-left:10px">      <span>}</span></div>
<div style="padding-left:10px"><br></div><div style="padding-left:10px">      <span>printf</span><span>(</span><span style="color:rgb(221,17,68)">"Delivery %u, exchange %.*s routingkey %.*s</span><span style="color:rgb(221,17,68)">\n</span><span style="color:rgb(221,17,68)">"</span><span>,</span></div>


<div style="padding-left:10px">             <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">unsigned</span><span>)</span> <span>envelope</span><span>.</span><span>delivery_tag</span><span>,</span></div>


<div style="padding-left:10px">             <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">int</span><span>)</span> <span>envelope</span><span>.</span><span>exchange</span><span>.</span><span>len</span><span>,</span> <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">char</span> <span style="font-weight:bold">*</span><span>)</span> <span>envelope</span><span>.</span><span>exchange</span><span>.</span><span>bytes</span><span>,</span></div>


<div style="padding-left:10px">             <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">int</span><span>)</span> <span>envelope</span><span>.</span><span>routing_key</span><span>.</span><span>len</span><span>,</span> <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">char</span> <span style="font-weight:bold">*</span><span>)</span> <span>envelope</span><span>.</span><span>routing_key</span><span>.</span><span>bytes</span><span>);</span></div>


<div style="padding-left:10px"><br></div><div style="padding-left:10px">      <span style="font-weight:bold">if</span> <span>(</span><span>envelope</span><span>.</span><span>message</span><span>.</span><span>properties</span><span>.</span><span>_flags</span> <span style="font-weight:bold">&</span> <span>AMQP_BASIC_CONTENT_TYPE_FLAG</span><span>)</span> <span>{</span></div>


<div style="padding-left:10px">        <span>printf</span><span>(</span><span style="color:rgb(221,17,68)">"Content-type: %.*s</span><span style="color:rgb(221,17,68)">\n</span><span style="color:rgb(221,17,68)">"</span><span>,</span></div>


<div style="padding-left:10px">               <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">int</span><span>)</span> <span>envelope</span><span>.</span><span>message</span><span>.</span><span>properties</span><span>.</span><span>content_type</span><span>.</span><span>len</span><span>,</span></div>


<div style="padding-left:10px">               <span>(</span><span style="color:rgb(68,85,136);font-weight:bold">char</span> <span style="font-weight:bold">*</span><span>)</span> <span>envelope</span><span>.</span><span>message</span><span>.</span><span>properties</span><span>.</span><span>content_type</span><span>.</span><span>bytes</span><span>);</span></div>


<div style="padding-left:10px">      <span>}</span></div><div style="padding-left:10px"><br></div><div style="padding-left:10px">      <span>amqp_destroy_envelope</span><span>(</span><span style="font-weight:bold">&</span><span>envelope</span><span>);</span></div>


<div style="padding-left:10px">    <span>}</span></div><div style="padding-left:10px">  <span>}</span></div></pre></div><div><br></div><div>First off, the output I'm getting when sending the string "Hello world" is <br>


</div><div><div>$ ./amqp_listen localhost 5672 amq.direct test</div><div>Delivery 1, exchange amq.direct routingkey test</div><div>Content-type: text/plain</div></div><div><br></div><div><br></div><div>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. </div>

</div></blockquote></div><div>The output is correct, it does not print out the body of the message. </div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>

</div><div>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?</div>

</div></blockquote></div><div>The if (AMQP_RESPONSE_NORMAL != res.reply_type) break; statement will break out of the loop if the message isn't received.</div><span class="HOEnZb"><font color="#888888"><div><br></div>
<div>-Alan </div></font></span></div></div></div>
<br>_______________________________________________<br>
rabbitmq-discuss mailing list<br>
<a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a><br>
<a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br>
<br></blockquote></div><br></div>