Make stuff to do things

Subscribe (?) Subscribe to RSS

Using prefetch with txAMQP and RabbitMQ 1.6.0

Published on August 14th, 2009 by Dan Reverri in Comments Tools:

I’m hoping this might be useful to someone. I wrote a quick script that uses “channel.basic_qos(prefetch_count=1)” with txAMQP and RabbitMQ 1.6.0. It is available here:
http://app.arat.us/blog/wp-content/uploads/2009/08/prefetch.py

You can run it as follows:

1
2
3
4
5
6
7
8
9
10
11
python prefetch.py localhost 5672 / guest guest path/to/specs/amqp0-8.xml
* Slow consumer received message: Message 1 *
Fast consumer received message: Message 2
Fast consumer received message: Message 3
* Slow consumer received message: Message 4 *
Fast consumer received message: Message 5
Fast consumer received message: Message 6
* Slow consumer received message: Message 7 *
Fast consumer received message: Message 8
Fast consumer received message: Message 9
* Slow consumer received message: Message 10 *

Notice that the fast consumer grabs twice as many messages as the slow consumer.

I have not found a clean way of ending the script, you have to force quit with CTRL+C. Let me know if you have any suggestions.

blog comments powered by Disqus
Switch to our mobile site