Created
June 5, 2013 10:43
-
-
Save dangerousbeans/5713056 to your computer and use it in GitHub Desktop.
Ruby AMQP Queue Priority
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "amqp" | |
EventMachine.run do | |
connection = AMQP.connect(:host => '127.0.0.1') | |
channel_low = AMQP::Channel.new(connection) | |
channel_high = AMQP::Channel.new(connection) | |
# Attempting to set the prefetch higher on the high priority queue | |
channel_low.prefetch(10) | |
channel_high.prefetch(20) | |
low_queue = channel_low.queue("low", :auto_delete => false) | |
high_queue = channel_high.queue("high", :auto_delete => false) | |
low_queue.subscribe do |payload| | |
puts "#{payload}" | |
slow_task | |
end | |
high_queue.subscribe do |payload| | |
puts "#{payload}" | |
slow_task | |
end | |
def slow_task | |
# Do some slow work | |
sleep(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment