Thanks Matthias for this very helpful and complete answer. I was actually not using AMQP, but STOMP... I guess the problem and the solution remain the same.<br>Do you think I should rather switch from Stomp to Amqp?<br><br>
Thanks,<br><br clear="all">--<br>Julien Genestoux<br><a href="http://www.ouvre-boite.com">http://www.ouvre-boite.com</a><br><a href="http://blog.notifixio.us">http://blog.notifixio.us</a><br><br>+1 (415) 254 7340<br>+33 (0)9 70 44 76 29<br>
<br><br><div class="gmail_quote">On Sun, Jan 18, 2009 at 1:41 AM, Matthias Radestock <span dir="ltr"><<a href="mailto:matthias@lshift.net">matthias@lshift.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Julien,<div class="Ih2E3d"><br>
<br>
Julien Genestoux wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
A process puts messages in a queue every second roughly. Atfer some time, I check the queue.<br>
> rabbitmqctl list_queues messages name consumers<br>
Listing queues ...<br>
508 /queue/MyQueue 0<br>
<br>
Now, I start a consumer with the following code :<br>
<br>
queue_client.subscribe("/queue/FeedsToParse", {:durable => true, "auto-delete".intern => false}) do |message|<br>
sleep 600<br>
puts "done!"<br>
end<br>
<br>
As you can see, when starting this client, the number of elements in my queue should decrease pretty slowly (1 every 10 minutes)... but here is what happens if I check the queue again:<br>
> rabbitmqctl list_queues messages name consumers<br>
Listing queues ...<br>
417 /queue/MyQueue 1<br>
<br>
So it seems that starting a consumer deletes some messages in the queue. I have no idea why. Can anyone explain?<br>
</blockquote>
<br></div>
The 'messages' count is the sum of:<br>
<br>
- messages_ready - Number of ready messages (i.e. messages ready to be delivered to client)<br>
<br>
- messages_unacknowledged - Number of unacknowledged messages.<br>
<br>
- messages_uncommitted - Number of uncommitted messages (i.e. messages published in a transaction but not yet committed)<br>
<br>
Since your example does not involve transactions, only messages_ready + messages_unacknowledged come into play.<br>
<br>
On publication, messages_ready increases.<br>
<br>
When delivering messages to a client, messages_ready decreases and messages_unacknowledged increases by the same amount, so the sum remains the same.<br>
<br>
When an acknowledgement is received from the client, messages_unacknowledged decreases, and so does the sum.<br>
<br>
Now ...<br>
<br>
I am familiar with Aman's ruby client, but looking at the code and docs it appears that by default the subscribe method creates a consumer from which the server does not expect acknowledgements (and indeed there is no explicit ack in the code above). Here's what ruby client's docs say;<br>
<br>
# == Options<br>
# * :ack => true | false (default false)<br>
# If this field is set to false the server does not expect acknowledgments<br>
# for messages. That is, when a message is delivered to the client<br>
# the server automatically and silently acknowledges it on behalf<br>
# of the client. This functionality increases performance but at<br>
# the cost of reliability. Messages can get lost if a client dies<br>
# before it can deliver them to the application.<br>
<br>
So as soon as your code creates the subscription, the server will start sending it the queue's messages (resulting in messages_ready to decrease) and automatically acknowledge all such messages (resulting in messages_unacknowledged to remain unchanged), and thus the 'messages' count decreases. This is an asynchronous operation; so the client will receive a stream of messages without having to do anything. The stream is only paused by network/tcp congestion, and basic.qos (search the archives for discussions on the latter).<br>
<br>
If that is not what you want I suggest you change the flag to true and explicitly acknowledge messages in your code.<br>
<br>
<br>
Regards,<br><font color="#888888">
<br>
Matthias<br>
</font></blockquote></div><br>