Class: Tootsie::AmqpQueue
- Inherits:
-
Object
- Object
- Tootsie::AmqpQueue
- Defined in:
- lib/tootsie/queues/amqp_queue.rb
Overview
A queue which uses the AMQP protocol.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(options = {}) ⇒ AmqpQueue
constructor
A new instance of AmqpQueue.
- #pop(options = {}) ⇒ Object
- #push(item) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AmqpQueue
Returns a new instance of AmqpQueue.
6 7 8 9 10 11 12 13 |
# File 'lib/tootsie/queues/amqp_queue.rb', line 6 def initialize( = {}) .assert_valid_keys(:host_name, :queue_name, :max_backoff) @backoff = Utility::Backoff.new(:max => [:max_backoff]) @logger = Application.get.logger @host_name = [:host_name] || 'localhost' @queue_name = [:queue_name] || 'tootsie' connect! end |
Instance Method Details
#count ⇒ Object
15 16 17 |
# File 'lib/tootsie/queues/amqp_queue.rb', line 15 def count nil end |
#pop(options = {}) ⇒ Object
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 |
# File 'lib/tootsie/queues/amqp_queue.rb', line 28 def pop( = {}) item = nil loop do @backoff.with do = nil with_retry do with_reconnect do = @queue.pop(:ack => true) end end if data = [:payload] data = nil if data == :queue_empty if data @logger.info "Popped: #{data.inspect}" item = JSON.parse(data) with_reconnect do @queue.ack(:delivery_tag => [:delivery_details][:delivery_tag]) end end end if item or not [:wait] true else false end end break if item end item end |
#push(item) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/tootsie/queues/amqp_queue.rb', line 19 def push(item) data = item.to_json with_retry do with_reconnect do @exchange.publish(data, :persistent => true, :key => @queue_name) end end end |