Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
Created June 8, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlhoerberg/0729156d1912fbd2af67 to your computer and use it in GitHub Desktop.
Save carlhoerberg/0729156d1912fbd2af67 to your computer and use it in GitHub Desktop.
Bunny workers
b = Bunny.new ENV.fetch 'CLOUDAMQP_URL', connection_timeout: 10
b.start
ch = b.create_channel # by default only one thread will be used per channel for processing messages
ch.prefetch 50
ch.queue('my-jobs', durable: true).subscribe(ack: true) do |delivery, headers, body|
data = JSON.parse body
process(data)
ch.ack delivery.delivery_tag
end
thread_pool_size = 10
ch2 = b.create_channel(nil, thread_pool_size)
# Use thread_pool_size number of threads to process messages on this queue in parallel
ch2.prefetch thread_pool_size + 30
ch2.queue('my-other-jobs', durable: true).subscribe(ack: true) do |delivery, headers, body|
data = JSON.parse body
process2(data)
ch.ack delivery.delivery_tag
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment