ok thanks for your help, that makes sense.<br><br><div class="gmail_quote">On 20 December 2010 16:42, Emile Joubert <span dir="ltr">&lt;<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Hi Fab,<br>
<br>
If you ran <a href="http://publish.pl" target="_blank">publish.pl</a> before <a href="http://consume.pl" target="_blank">consume.pl</a> then the messages will be discarded, because there is no queue for messages to be delivered to and no binding for messages to get there.<br>

<br>
As Alexandru explained, the binding and queue have to exist first. You could either launch the consumer in the background before starting the publisher, or declare the queue and binding in the publisher as well.<br>
<br>
Regards<br>
<br>
Emile<br>
<br>
<br>
<br>
Op 20/12/2010 16:11, het Alexandru Scvorţov geskryf:<div><div></div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Queues and exchanges don&#39;t work like that.<br>
<br>
An exchange is just a router, it doesn&#39;t store messages.  That&#39;s the<br>
queues&#39; job.<br>
<br>
What you want to do is this:<br>
   - publisher declares a durable queue with a known name and binds it to an<br>
     exchange (by default it&#39;s bound the default exchange with its name<br>
     as routing key; the default exchange is &quot;amq.default&quot; or &quot;&quot;)<br>
   - publisher publishes a persistent message to the exchange, which<br>
     routes it to the queue (the routing key should be the queue&#39;s name,<br>
     or whatever you bound the queue with)<br>
<br>
   - consumer declares a durable queue with the same name (this is just<br>
     to make sure that it exists; it&#39;s effectively a no-op)<br>
   - consumer consumes or gets from the queue.<br>
<br>
Hope this helps.<br>
<br>
Cheers,<br>
Alex<br>
<br>
On Mon, Dec 20, 2010 at 03:38:11PM +0000, underattack7 wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I am struggling with persistent message in perl.<br>
<br>
What I am trying to achieve is :<br>
- publish message to a direct exchange<br>
- the exchange stores the message<br>
- a consumer creates a queue, binds it to the exchange, and get all the<br>
stored messages<br>
<br>
I have a durable exchange, and apparently I would need to publish message<br>
using &quot;delivery_mode = 2&quot; for the exchange to store the message until a<br>
queue is bound to it....is that right ?<br>
<br>
The problem I have is that when my consumer creates a queue and bind it to<br>
the exchange, it does not get all the message sent.<br>
<br>
<br>
My publisher code :<br>
<br>
#!/usr/bin/perl<br>
use Net::RabbitMQ;<br>
<br>
my $myexchange=$ARGV[0];<br>
my $rkey=$ARGV[1];<br>
my $text=$ARGV[2];<br>
<br>
my $mq = Net::RabbitMQ-&gt;new();<br>
$mq-&gt;connect(&quot;rabbitmqserver&quot;, { vhost=&gt;&quot;chat&quot;, user =&gt;  &quot;guest&quot;, password =&gt;<br>
&quot;guest&quot; });<br>
$mq-&gt;channel_open(1);<br>
$mq-&gt;publish(1, $rkey, $text, {exchange =&gt;  $myexchange}, { content_type =&gt;<br>
&#39;text/plain&#39;, delivery_mode =&gt;  2});<br>
mqdisconnect;<br>
exit 0;<br>
<br>
<br>
I execute it with for example :<br>
./<a href="http://publish.pl" target="_blank">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto1&quot;<br>
./<a href="http://publish.pl" target="_blank">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto2&quot;<br>
./<a href="http://publish.pl" target="_blank">publish.pl</a> &quot;exchangechat&quot; &quot;toto&quot; &quot;hi toto3&quot;<br>
<br>
<br>
<br>
The consumer code is :<br>
#!/usr/bin/perl<br>
use Net::RabbitMQ;<br>
<br>
my $exchange=$ARGV[0];<br>
my $rkey=$ARGV[1];<br>
<br>
my $mq = Net::RabbitMQ-&gt;new();<br>
$mq-&gt;connect(&quot;rabbitmqserver&quot;, { vhost =&gt;  &quot;chat&quot;, user =&gt;  &quot;guest&quot;, password<br>
=&gt;  &quot;guest&quot; });<br>
$mq-&gt;channel_open(1);<br>
my $queuename = $mq-&gt;queue_declare(1, &#39;&#39;, {exclusive =&gt;  1, durable =&gt;  0,<br>
auto_delete =&gt;  1});<br>
$mq-&gt;queue_bind(1, &quot;$queue&quot;, &quot;$exchange&quot;, &quot;$rkey&quot;);<br>
<br>
while(1) {<br>
     my $message = $mq-&gt;get(1, $queuename);<br>
     if ( defined($message) ) {<br>
         print $message-&gt;{&#39;routing_key&#39;} . &quot;\n&quot;;<br>
         print $message-&gt;{&#39;body&#39;} . &quot;\n&quot;;<br>
         print &quot;\n\n&quot;;<br>
     }<br>
     sleep(1);<br>
}<br>
exit 0;<br>
<br>
And I run it with :<br>
./<a href="http://consume.pl" target="_blank">consume.pl</a> exchangechat &quot;toto&quot;<br>
<br>
but I do not get the message &quot;hi toto1&quot;<br>
<br>
<br>
Any idea what&#39;s wrong here ?<br>
<br>
Thanks,<br>
<br>
Fab<br>
</blockquote></blockquote>
</div></div></blockquote></div><br>