Class: RServiceBus2::EndpointMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/endpointmapping.rb

Overview

Marshals data for message end points Expected format: <msg mame 1>:<end point 1>;<msg mame 2>:<end point 2>

Instance Method Summary collapse

Constructor Details

#initializeEndpointMapping

rubocop:enable Metrics/MethodLength



64
65
66
# File 'lib/rservicebus2/endpointmapping.rb', line 64

def initialize
  @endpoints = {}
end

Instance Method Details

#configure(local_queue_name = nil) ⇒ Object

rubocop:disable Metrics/MethodLength



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rservicebus2/endpointmapping.rb', line 41

def configure(local_queue_name = nil)
  log('EndpointMapping.Configure')

  @queue_name_list = []
  @queue_name_list << local_queue_name unless local_queue_name.nil?

  unless get_value('MESSAGE_ENDPOINT_MAPPING').nil?
    log '*** MESSAGE_ENDPOINT_MAPPING environment variable was detected\n' \
        "*** You may have intended MESSAGE_ENDPOINT_MAPPINGS, note the 'S'
          on the end"
  end

  mappings = get_value('MESSAGE_ENDPOINT_MAPPINGS')
  return self if mappings.nil?

  mappings.split(';').each do |mapping|
    configure_mapping(mapping)
  end

  self
end

#configure_mapping(mapping) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rservicebus2/endpointmapping.rb', line 16

def configure_mapping(mapping)
  match = mapping.match(/(.+):(.+)/)
  if match.nil?
    log 'Mapping string provided is invalid\n' \
        "The entire mapping string is: #{mapping}\n" \
        "*** Could not find ':' in mapping entry, #{line}\n"
    exit
  end

  RServiceBus2.rlog "EndpointMapping.configureMapping: #{match[1]}, #{match[2]}"
  @endpoints[match[1]] = match[2]

  @queue_name_list.each do |q|
    next unless q != match[2] && q.downcase == match[2].downcase

    log('*** Two queues specified with only case sensitive difference.')
    log("*** #{q} != #{match[2]}")
    log('*** If you meant these queues to be the same, please match case
          and restart the bus.')
  end
  @queue_name_list << match[2]
end

#get(msg_name) ⇒ Object



68
69
70
71
72
# File 'lib/rservicebus2/endpointmapping.rb', line 68

def get(msg_name)
  return @endpoints[msg_name] if @endpoints.key?(msg_name)

  nil
end

#get_value(name) ⇒ Object



7
8
9
# File 'lib/rservicebus2/endpointmapping.rb', line 7

def get_value(name)
  RServiceBus2.get_value(name)
end

#log(string, _ver: false) ⇒ Object



11
12
13
# File 'lib/rservicebus2/endpointmapping.rb', line 11

def log(string, _ver: false)
  RServiceBus2.log(string)
end

#subscription_endpointsObject



74
75
76
# File 'lib/rservicebus2/endpointmapping.rb', line 74

def subscription_endpoints
  @endpoints.keys.select { |el| el.end_with?('Event') }
end