Skip to content

Instantly share code, notes, and snippets.

@dangerousbeans
Created June 5, 2013 10:43
Show Gist options
  • Save dangerousbeans/5713056 to your computer and use it in GitHub Desktop.
Save dangerousbeans/5713056 to your computer and use it in GitHub Desktop.
Ruby AMQP Queue Priority
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