Module: Legion::Transport::TenantTopology

Extended by:
Logging::Helper
Defined in:
lib/legion/transport/tenant_topology.rb

Constant Summary collapse

SHARED_EXCHANGES =
%w[legion.control legion.health legion.audit].freeze

Class Method Summary collapse

Class Method Details

.current_tenant_idObject



39
40
41
42
43
44
45
46
# File 'lib/legion/transport/tenant_topology.rb', line 39

def self.current_tenant_id
  return nil unless defined?(Legion::TenantContext)

  Legion::TenantContext.current_tenant_id
rescue StandardError => e
  handle_exception(e, level: :warn, handled: true, operation: :tenant_topology_current_tenant_id)
  nil
end

.enabled?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/legion/transport/tenant_topology.rb', line 34

def self.enabled?
  settings = transport_settings
  settings.is_a?(Hash) && settings.dig(:tenant_topology, :enabled) == true
end

.exchange_name(base_name, tenant_id: nil) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/legion/transport/tenant_topology.rb', line 12

def self.exchange_name(base_name, tenant_id: nil)
  return base_name unless enabled?

  tid = tenant_id || current_tenant_id
  return base_name if tid.nil? || tid == 'default' || shared?(base_name)

  "t.#{tid}.#{base_name}"
end

.queue_name(base_name, tenant_id: nil) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/legion/transport/tenant_topology.rb', line 21

def self.queue_name(base_name, tenant_id: nil)
  return base_name unless enabled?

  tid = tenant_id || current_tenant_id
  return base_name if tid.nil? || tid == 'default'

  "t.#{tid}.#{base_name}"
end

.shared?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legion/transport/tenant_topology.rb', line 30

def self.shared?(name)
  SHARED_EXCHANGES.any? { |prefix| name.start_with?(prefix) }
end