Created
June 8, 2014 13:37
-
-
Save carlhoerberg/0729156d1912fbd2af67 to your computer and use it in GitHub Desktop.
Bunny workers
This file contains 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
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