Class: Moqueue::MockExchange

Inherits:
Object
  • Object
show all
Defined in:
lib/moqueue/mock_exchange.rb

Defined Under Namespace

Classes: BindingKey

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ MockExchange

Returns a new instance of MockExchange.



22
23
24
25
26
27
28
# File 'lib/moqueue/mock_exchange.rb', line 22

def initialize(opts={})
  if @topic = opts[:topic]
    MockBroker.instance.register_topic_exchange(self)
  elsif @fanout = opts[:fanout]
    MockBroker.instance.register_fanout_exchange(self)
  end
end

Instance Attribute Details

#fanoutObject (readonly)

Returns the value of attribute fanout.



4
5
6
# File 'lib/moqueue/mock_exchange.rb', line 4

def fanout
  @fanout
end

#topicObject (readonly)

Returns the value of attribute topic.



4
5
6
# File 'lib/moqueue/mock_exchange.rb', line 4

def topic
  @topic
end

Class Method Details

.new(opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/moqueue/mock_exchange.rb', line 8

def new(opts={})
  if opts[:topic] && topic_exchange = MockBroker.instance.find_topic_exchange(opts[:topic])
    return topic_exchange
  end
  
  if opts[:fanout] && fanout = MockBroker.instance.find_fanout_exchange(opts[:fanout])
    return fanout
  end
  
  super
end

Instance Method Details

#acked_messagesObject



34
35
36
# File 'lib/moqueue/mock_exchange.rb', line 34

def acked_messages
  @acked_messages ||= []
end

#attach_queue(queue, opts = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/moqueue/mock_exchange.rb', line 38

def attach_queue(queue, opts={})
  if topic
    attached_queues << [queue, BindingKey.new(opts[:key])]
  else
    attached_queues << queue
  end
end

#attached_queuesObject



30
31
32
# File 'lib/moqueue/mock_exchange.rb', line 30

def attached_queues
  @attached_queues ||= []
end

#publish(message, opts = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/moqueue/mock_exchange.rb', line 46

def publish(message, opts={})
  require_routing_key(opts) if topic
  matching_queues(opts).each do |q| 
    ack_message(q.receive(message, prepare_header_opts(opts)))
  end
end

#received_ack_for_message?(message) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/moqueue/mock_exchange.rb', line 53

def received_ack_for_message?(message)
  acked_messages.include?(message)
end