Module: HireFire::Macro::Bunny
Instance Method Summary collapse
- #count_messages(channel, queue_names, options) ⇒ Object
-
#queue(*queues) ⇒ Integer
Returns the job quantity for the provided queue(s).
Instance Method Details
#count_messages(channel, queue_names, options) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/hirefire/macro/bunny.rb', line 71 def (channel, queue_names, ) queue_names.inject(0) do |sum, queue_name| queue = channel.queue(queue_name, :durable => [:durable]) sum + queue. end end |
#queue(*queues) ⇒ Integer
Returns the job quantity for the provided queue(s).
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hirefire/macro/bunny.rb', line 25 def queue(*queues) require "bunny" queues.flatten! if queues.last.is_a?(Hash) = queues.pop else = {} end if [:durable].nil? [:durable] = true end if [:connection] connection = [:connection] channel = nil begin channel = connection.create_channel return (channel, queues, ) ensure if channel channel.close end end elsif [:amqp_url] connection = ::Bunny.new([:amqp_url]) begin connection.start channel = connection.create_channel return (channel, queues, ) ensure if channel channel.close end connection.close end else raise %{Must pass in :connection => rabbitmq_connection or :amqp_url => url\n} + %{For example: HireFire::Macro::Bunny.queue("queue1", :connection => rabbitmq_connection} end end |