module Legion::Transport::Settings

Public Class Methods

channel() click to toggle source
# File lib/legion/transport/settings.rb, line 38
def self.channel
  {
    default_worker_pool_size: ENV['transport.channel.default_worker_pool_size'] || 1,
    session_worker_pool_size: ENV['transport.channel.session_worker_pool_size'] || 8
  }
end
connection() click to toggle source
# File lib/legion/transport/settings.rb, line 6
def self.connection
  {
    read_timeout: 1,
    heartbeat: 30,
    automatically_recover: true,
    continuation_timeout: 4000,
    network_recovery_interval: 1,
    connection_timeout: 1,
    frame_max: 65_536,
    user: ENV['transport.connection.user'] || 'guest',
    password: ENV['transport.connection.password'] || 'guest',
    host: ENV['transport.connection.host'] || '127.0.0.1',
    port: ENV['transport.connection.port'] || '5672',
    vhost: ENV['transport.connection.vhost'] || '/',
    recovery_attempts: 100,
    logger_level: ENV['transport.log_level'] || 'info',
    connected: false
  }.merge(grab_vault_creds)
end
default() click to toggle source
# File lib/legion/transport/settings.rb, line 75
def self.default
  {
    type: 'rabbitmq',
    connected: false,
    logger_level: ENV['transport.logger_level'] || 'info',
    messages: messages,
    prefetch: ENV['transport.prefetch'].to_i || 2,
    exchanges: exchanges,
    queues: queues,
    connection: connection,
    channel: channel
  }
end
exchanges() click to toggle source
# File lib/legion/transport/settings.rb, line 56
def self.exchanges
  {
    type: 'topic',
    arguments: {},
    auto_delete: false,
    durable: true,
    internal: false
  }
end
grab_vault_creds() click to toggle source
# File lib/legion/transport/settings.rb, line 26
def self.grab_vault_creds
  return {} unless Legion::Settings[:crypt][:vault][:connected]

  Legion::Transport.logger.info 'Attempting to grab RabbitMQ creds from vault'
  lease = Legion::Crypt.read('rabbitmq/creds/legion', type: nil)
  Legion::Transport.logger.debug 'successfully grabbed amqp username from Vault'
  { user: lease[:username], password: lease[:password] }
rescue StandardError
  Legion::Transport.logger.warn 'Error reading rabbitmq creds from vault'
  {}
end
messages() click to toggle source
# File lib/legion/transport/settings.rb, line 66
def self.messages
  {
    encrypt: ENV['transport.messsages.encrypt'] == 'true',
    ttl: ENV['transport.messages.ttl'],
    priority: ENV['transport.messages.priority'].to_i || 0,
    persistent: ENV['transport.messages.persistent'] == 'true'
  }
end
queues() click to toggle source
# File lib/legion/transport/settings.rb, line 45
def self.queues
  {
    manual_ack: true,
    durable: true,
    exclusive: false,
    block: false,
    auto_delete: false,
    arguments: { 'x-max-priority': 255, 'x-overflow': 'reject-publish' }
  }
end