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 "delivery_mode = 2" 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->new();</div>
<div>$mq->connect("rabbitmqserver", { vhost=>"chat", user => "guest", password => "guest" });</div><div>$mq->channel_open(1);</div><div>$mq->publish(1, $rkey, $text, {exchange => $myexchange}, { content_type => 'text/plain', delivery_mode => 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> "exchangechat" "toto" "hi toto1"</div>
<div>./<a href="http://publish.pl">publish.pl</a> "exchangechat" "toto" "hi toto2"</div><div>./<a href="http://publish.pl">publish.pl</a> "exchangechat" "toto" "hi toto3"</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->new();</div><div>$mq->connect("rabbitmqserver", { vhost => "chat", user => "guest", password => "guest" });</div><div>$mq->channel_open(1);</div>
<div>my $queuename = $mq->queue_declare(1, '', {exclusive => 1, durable => 0, auto_delete => 1});</div><div>$mq->queue_bind(1, "$queue", "$exchange", "$rkey");</div><div>
<br></div><div>while(1) {</div><div> my $message = $mq->get(1, $queuename);</div><div> if ( defined($message) ) {</div><div> print $message->{'routing_key'} . "\n";</div><div> print $message->{'body'} . "\n";</div>
<div> print "\n\n";</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 "toto"</div>
<div><br></div><div>but I do not get the message "hi toto1"</div><div><br></div><div><br></div><div>Any idea what's wrong here ?</div><div><br></div><div>Thanks,</div><div><br></div><div>Fab</div><div><br></div>
<div><br></div>