Class: Harmoniser::Topology

Inherits:
Object
  • Object
show all
Includes:
Connectable
Defined in:
lib/harmoniser/topology.rb

Constant Summary

Constants included from Connectable

Connectable::MUTEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connectable

included

Constructor Details

#initializeTopology

Returns a new instance of Topology.



10
11
12
13
14
# File 'lib/harmoniser/topology.rb', line 10

def initialize
  @bindings = Set.new
  @exchanges = Set.new
  @queues = Set.new
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



8
9
10
# File 'lib/harmoniser/topology.rb', line 8

def bindings
  @bindings
end

#exchangesObject (readonly)

Returns the value of attribute exchanges.



8
9
10
# File 'lib/harmoniser/topology.rb', line 8

def exchanges
  @exchanges
end

#queuesObject (readonly)

Returns the value of attribute queues.



8
9
10
# File 'lib/harmoniser/topology.rb', line 8

def queues
  @queues
end

Instance Method Details

#add_binding(exchange_name, destination_name, destination_type = :queue, **opts) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/harmoniser/topology.rb', line 33

def add_binding(exchange_name, destination_name, destination_type = :queue, **opts)
  @bindings << Definition::Binding.new(
    exchange_name: exchange_name,
    destination_name: destination_name,
    destination_type: destination_type,
    opts: opts
  )
  self
end

#add_exchange(type, name, **opts) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/harmoniser/topology.rb', line 16

def add_exchange(type, name, **opts)
  @exchanges << Definition::Exchange.new(
    type: type,
    name: name,
    opts: opts
  )
  self
end

#add_queue(name, **opts) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/harmoniser/topology.rb', line 25

def add_queue(name, **opts)
  @queues << Definition::Queue.new(
    name: name,
    opts: opts
  )
  self
end

#declareObject



43
44
45
46
47
48
49
50
# File 'lib/harmoniser/topology.rb', line 43

def declare
  self.class.create_channel.tap do |ch|
    declare_exchanges(ch)
    declare_queues(ch)
    declare_bindings(ch)
    ch.connection.close
  end
end