Sha256: 2096b340fe638f9eba5ed567ea269ab2278ac0ba6926243b2084540c5988dc1c

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

require 'legion/settings'

module Legion
  module Transport
    module Settings
      # Legion::Settings.merge_settings('transport', default) if Legion::Settings.method_defined? :merge_settings
      def self.connection
        {
          read_timeout: 1,
          heartbeat: 1,
          automatically_recover: true,
          continuation_timeout: 4000,
          network_recovery_interval: 1,
          connection_timeout: 1,
          user: 'guest',
          password: 'guest',
          host: '127.0.0.1',
          port: '5672',
          vhost: 'legion',
          recovery_attempts: 0,
          logger_level: 'info'
        }.merge(grab_vault_creds)
      end

      def self.grab_vault_creds
        return {} unless Legion::Settings[:crypt][:vault][:connected]

        lease = Legion::Crypt.read('rabbitmq/creds/legion', type: nil)
        Legion::Logging.debug 'successfully grabbed amqp username from Vault'
        { user: lease[:username], password: lease[:password] }
      rescue StandardError
        {}
      end

      def self.default
        {
          type: 'rabbitmq',
          connected: false,
          logger_level: 'info',
          messages: {
            encrypt: false,
            ttl: nil,
            priority: 0
          },
          exchanges: {
            type: 'topic',
            arguments: {},
            auto_delete: false,
            durable: true,
            internal: false
          },
          queues: {
            manual_ack: true,
            durable: true,
            exclusive: false,
            block: false,
            auto_delete: false,
            arguments: { 'x-max-priority': 255, 'x-overflow': 'reject-publish' }
          },
          prefetch: 2,
          connection: connection
        }
      end
    end
  end
end

begin
  Legion::Settings.merge_settings('transport', Legion::Transport::Settings.default) if Legion.const_defined?('Settings')
rescue StandardError => e
  Legion::Logging.fatal(e.message) if Legion::Logging.method_defined?(:fatal)
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
legion-transport-1.1.5 lib/legion/transport/settings.rb
legion-transport-java-1.1.4 lib/legion/transport/settings.rb
legion-transport-1.1.4 lib/legion/transport/settings.rb