Hi,<div><br></div><div>I am struggling with persistent message in perl.</div><div><br></div><div>What I am trying to achieve is :</div><div>- publish message to a direct exchange</div><div>- the exchange stores the message</div>
<div>- a consumer creates a queue, binds it to the exchange, and get all the stored messages</div><div><br></div><div>I have a durable exchange, and apparently I would need to publish message using &quot;delivery_mode = 2&quot; for the exchange to store the message until a queue is bound to it....is that right ?</div>
<div><br></div><div>The problem I have is that when my consumer creates a queue and bind it to the exchange, it does not get all the message sent.</div><div><br></div><div><br></div><div>My publisher code :</div><div><br>
</div><div><div>#!/usr/bin/perl</div><div>use Net::RabbitMQ;</div><div><br></div><div>my $myexchange=$ARGV[0];</div><div>my $rkey=$ARGV[1];</div><div>my $text=$ARGV[2];</div><div><br></div><div>my $mq = Net::RabbitMQ-&gt;new();</div>
<div>$mq-&gt;connect(&quot;rabbitmqserver&quot;, { vhost=&gt;&quot;chat&quot;, user =&gt; &quot;guest&quot;, password =&gt; &quot;guest&quot; });</div><div>$mq-&gt;channel_open(1);</div><div>$mq-&gt;publish(1, $rkey, $text, {exchange =&gt; $myexchange}, { content_type =&gt; &#39;text/plain&#39;, delivery_mode =&gt; 2});</div>
<div>mqdisconnect;</div><div>exit 0;�</div></div><div><br></div><div><br></div><div>I execute it with for example :</div><div>./<a href="http://publish.pl">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto1&quot;</div>
<div>./<a href="http://publish.pl">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto2&quot;</div><div>./<a href="http://publish.pl">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto3&quot;</div>
<div><br></div><div><br></div><div><br></div><div>The consumer code is :</div><div><div>#!/usr/bin/perl</div><div>use Net::RabbitMQ;</div><div><br></div><div>my $exchange=$ARGV[0];</div><div>my $rkey=$ARGV[1];</div><div><br>
</div><div>my $mq = Net::RabbitMQ-&gt;new();</div><div>$mq-&gt;connect(&quot;rabbitmqserver&quot;, { vhost =&gt; &quot;chat&quot;, user =&gt; &quot;guest&quot;, password =&gt; &quot;guest&quot; });</div><div>$mq-&gt;channel_open(1);</div>
<div>my $queuename = $mq-&gt;queue_declare(1, &#39;&#39;, {exclusive =&gt; 1, durable =&gt; 0, auto_delete =&gt; 1});</div><div>$mq-&gt;queue_bind(1, &quot;$queue&quot;, &quot;$exchange&quot;, &quot;$rkey&quot;);</div><div>
<br></div><div>while(1) {</div><div>�� �my $message = $mq-&gt;get(1, $queuename);</div><div>�� �if ( defined($message) ) {</div><div>�� � � �print $message-&gt;{&#39;routing_key&#39;} . &quot;\n&quot;;</div><div>�� � � �print $message-&gt;{&#39;body&#39;} . &quot;\n&quot;;</div>
<div>�� � � �print &quot;\n\n&quot;;</div><div>�� �}</div><div>�� �sleep(1);�</div><div>}</div><div>exit 0;</div></div><div><br></div><div>And I run it with :</div><div>./<a href="http://consume.pl">consume.pl</a> exchangechat &quot;toto&quot;</div>
<div><br></div><div>but I do not get the message &quot;hi toto1&quot;</div><div><br></div><div><br></div><div>Any idea what&#39;s wrong here ?</div><div><br></div><div>Thanks,</div><div><br></div><div>Fab</div><div><br></div>
<div><br></div>