Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.