<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 class="" id="LC106" style="padding-left:10px">  <span class="" style>{</span></div><div class="" id="LC107" style="padding-left:10px">    <span class="" style="font-weight:bold">while</span> <span class="" style>(</span><span class="" style="color:rgb(0,153,153)">1</span><span class="" style>)</span> <span class="" style>{</span></div>
<div class="" id="LC108" style="padding-left:10px">      <span class="" style="color:rgb(68,85,136);font-weight:bold">amqp_rpc_reply_t</span> <span class="" style>res</span><span class="" style>;</span></div><div class="" id="LC109" style="padding-left:10px">
      <span class="" style="color:rgb(68,85,136);font-weight:bold">amqp_envelope_t</span> <span class="" style>envelope</span><span class="" style>;</span></div><div class="" id="LC110" style="padding-left:10px"><br style>
</div><div class="" id="LC111" style="padding-left:10px">      <span class="" style>amqp_maybe_release_buffers</span><span class="" style>(</span><span class="" style>conn</span><span class="" style>);</span></div><div class="" id="LC112" style="padding-left:10px">
<br style></div><div class="" id="LC113" style="padding-left:10px">      <span class="" style>res</span> <span class="" style="font-weight:bold">=</span> <span class="" style>amqp_consume_message</span><span class="" style>(</span><span class="" style>conn</span><span class="" style>,</span> <span class="" style="font-weight:bold">&</span><span class="" style>envelope</span><span class="" style>,</span> <span class="" style="color:rgb(0,134,179)">NULL</span><span class="" style>,</span> <span class="" style="color:rgb(0,153,153)">0</span><span class="" style>);</span></div>
<div class="" id="LC114" style="padding-left:10px"><br style></div><div class="" id="LC115" style="padding-left:10px">      <span class="" style="font-weight:bold">if</span> <span class="" style>(</span><span class="" style>AMQP_RESPONSE_NORMAL</span> <span class="" style="font-weight:bold">!=</span> <span class="" style>res</span><span class="" style>.</span><span class="" style>reply_type</span><span class="" style>)</span> <span class="" style>{</span></div>
<div class="" id="LC116" style="padding-left:10px">        <span class="" style="font-weight:bold">break</span><span class="" style>;</span></div><div class="" id="LC117" style="padding-left:10px">      <span class="" style>}</span></div>
<div class="" id="LC118" style="padding-left:10px"><br style></div><div class="" id="LC119" style="padding-left:10px">      <span class="" style>printf</span><span class="" style>(</span><span class="" style="color:rgb(221,17,68)">"Delivery %u, exchange %.*s routingkey %.*s</span><span class="" style="color:rgb(221,17,68)">\n</span><span class="" style="color:rgb(221,17,68)">"</span><span class="" style>,</span></div>
<div class="" id="LC120" style="padding-left:10px">             <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">unsigned</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>delivery_tag</span><span class="" style>,</span></div>
<div class="" id="LC121" style="padding-left:10px">             <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">int</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>exchange</span><span class="" style>.</span><span class="" style>len</span><span class="" style>,</span> <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">char</span> <span class="" style="font-weight:bold">*</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>exchange</span><span class="" style>.</span><span class="" style>bytes</span><span class="" style>,</span></div>
<div class="" id="LC122" style="padding-left:10px">             <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">int</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>routing_key</span><span class="" style>.</span><span class="" style>len</span><span class="" style>,</span> <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">char</span> <span class="" style="font-weight:bold">*</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>routing_key</span><span class="" style>.</span><span class="" style>bytes</span><span class="" style>);</span></div>
<div class="" id="LC123" style="padding-left:10px"><br style></div><div class="" id="LC124" style="padding-left:10px">      <span class="" style="font-weight:bold">if</span> <span class="" style>(</span><span class="" style>envelope</span><span class="" style>.</span><span class="" style>message</span><span class="" style>.</span><span class="" style>properties</span><span class="" style>.</span><span class="" style>_flags</span> <span class="" style="font-weight:bold">&</span> <span class="" style>AMQP_BASIC_CONTENT_TYPE_FLAG</span><span class="" style>)</span> <span class="" style>{</span></div>
<div class="" id="LC125" style="padding-left:10px">        <span class="" style>printf</span><span class="" style>(</span><span class="" style="color:rgb(221,17,68)">"Content-type: %.*s</span><span class="" style="color:rgb(221,17,68)">\n</span><span class="" style="color:rgb(221,17,68)">"</span><span class="" style>,</span></div>
<div class="" id="LC126" style="padding-left:10px">               <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">int</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>message</span><span class="" style>.</span><span class="" style>properties</span><span class="" style>.</span><span class="" style>content_type</span><span class="" style>.</span><span class="" style>len</span><span class="" style>,</span></div>
<div class="" id="LC127" style="padding-left:10px">               <span class="" style>(</span><span class="" style="color:rgb(68,85,136);font-weight:bold">char</span> <span class="" style="font-weight:bold">*</span><span class="" style>)</span> <span class="" style>envelope</span><span class="" style>.</span><span class="" style>message</span><span class="" style>.</span><span class="" style>properties</span><span class="" style>.</span><span class="" style>content_type</span><span class="" style>.</span><span class="" style>bytes</span><span class="" style>);</span></div>
<div class="" id="LC128" style="padding-left:10px">      <span class="" style>}</span></div><div class="" id="LC129" style="padding-left:10px"><br style></div><div class="" id="LC130" style="padding-left:10px">      <span class="" style>amqp_destroy_envelope</span><span class="" style>(</span><span class="" style="font-weight:bold">&</span><span class="" style>envelope</span><span class="" style>);</span></div>
<div class="" id="LC131" style="padding-left:10px">    <span class="" style>}</span></div><div class="" id="LC132" style="padding-left:10px">  <span class="" style>}</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. <br>
</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><br></div><div><br></div><div><br></div><div>Thank you,</div><div><br></div></div>