Class: ReliableMsg::MultiQueue

Inherits:
Client
  • Object
show all
Defined in:
lib/ap4r/multi_queue.rb

Overview

The MultiQueue is a kind of clients. This offers two extentions to ReliableMsg::Queue

  1. specify multiple target queues, by as comma-separated queue names.

  2. specify prefix of a collection of queues by an asterisk at the end.

Exapmles:

  • "a.b.c" targets single queue.

  • "a.b.c, x.y.z" targets two queues.

  • "a.b.*" targets a collection of queues such as “a.b.c”, “a.b.d”, etc.

  • "a.b.*, x.y.*" targets two collections.

Instance Method Summary collapse

Constructor Details

#initialize(multi_queue, options = nil) ⇒ MultiQueue

Creates a new MultiQueue with target queues specified by multi_queue. See ReliableMsg::Queue for options.



19
20
21
22
# File 'lib/ap4r/multi_queue.rb', line 19

def initialize multi_queue, options = nil
  @multi_queue = multi_queue
  @options = options
end

Instance Method Details

#get(selector = nil, &block) ⇒ Object

Gets a message from target queues. Internally, first search a queue with the most stale message, and get a message from the queue by ReliableMsg::Queue#get



27
28
29
30
31
32
33
34
# File 'lib/ap4r/multi_queue.rb', line 27

def get selector = nil, &block
  queue_name = repeated {|qm|
    qm.stale_queue @multi_queue
  }
  return nil unless queue_name
  queue = Queue.new queue_name, @options
  queue.get selector, &block
end

#nameObject

Returns multi queue expression as String.



37
38
39
# File 'lib/ap4r/multi_queue.rb', line 37

def name
  @multi_queue
end