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"><<a href="mailto:emile@rabbitmq.com">emile@rabbitmq.com</a>></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't work like that.<br>
<br>
An exchange is just a router, it doesn't store messages. That's the<br>
queues' 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's bound the default exchange with its name<br>
as routing key; the default exchange is "amq.default" or "")<br>
- publisher publishes a persistent message to the exchange, which<br>
routes it to the queue (the routing key should be the queue'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'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 "delivery_mode = 2" 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->new();<br>
$mq->connect("rabbitmqserver", { vhost=>"chat", user => "guest", password =><br>
"guest" });<br>
$mq->channel_open(1);<br>
$mq->publish(1, $rkey, $text, {exchange => $myexchange}, { content_type =><br>
'text/plain', delivery_mode => 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> "exchangechat" "toto" "hi toto1"<br>
./<a href="http://publish.pl" target="_blank">publish.pl</a> "exchangechat" "toto" "hi toto2"<br>
./<a href="http://publish.pl" target="_blank">publish.pl</a> "exchangechat" "toto" "hi toto3"<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->new();<br>
$mq->connect("rabbitmqserver", { vhost => "chat", user => "guest", password<br>
=> "guest" });<br>
$mq->channel_open(1);<br>
my $queuename = $mq->queue_declare(1, '', {exclusive => 1, durable => 0,<br>
auto_delete => 1});<br>
$mq->queue_bind(1, "$queue", "$exchange", "$rkey");<br>
<br>
while(1) {<br>
my $message = $mq->get(1, $queuename);<br>
if ( defined($message) ) {<br>
print $message->{'routing_key'} . "\n";<br>
print $message->{'body'} . "\n";<br>
print "\n\n";<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 "toto"<br>
<br>
but I do not get the message "hi toto1"<br>
<br>
<br>
Any idea what's wrong here ?<br>
<br>
Thanks,<br>
<br>
Fab<br>
</blockquote></blockquote>
</div></div></blockquote></div><br>