Class: ActivePublisher::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_publisher/configuration.rb

Constant Summary collapse

CONFIGURATION_MUTEX =
::Mutex.new
NETWORK_RECOVERY_INTERVAL =
1.freeze
DEFAULTS =
{
  :error_handler => lambda { |error, env_hash|
    ::ActivePublisher::Logging.logger.error(error.class)
    ::ActivePublisher::Logging.logger.error(error.message)
    ::ActivePublisher::Logging.logger.error(error.backtrace.join("\n")) if error.backtrace.respond_to?(:join)
  },
  :heartbeat => 5,
  :host => "localhost",
  :hosts => [],
  :password => "guest",
  :messages_per_batch => 25,
  :max_async_publisher_lag_time => 10,
  :network_recovery_interval => NETWORK_RECOVERY_INTERVAL,
  :port => 5672,
  :publisher_threads => 1,
  :publisher_confirms => false,
  :publisher_confirms_timeout => 5_000, #specified as a number of milliseconds
  :seconds_to_wait_for_graceful_shutdown => 30,
  :timeout => 1,
  :tls => false,
  :tls_ca_certificates => [],
  :tls_cert => nil,
  :tls_key => nil,
  :username => "guest",
  :verify_peer => true,
  :virtual_host => "/"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Instance Methods



117
118
119
120
121
# File 'lib/active_publisher/configuration.rb', line 117

def initialize
  DEFAULTS.each_pair do |key, value|
    self.__send__("#{key}=", value)
  end
end

Instance Attribute Details

#error_handlerObject

Returns the value of attribute error_handler.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def error_handler
  @error_handler
end

#heartbeatObject

Returns the value of attribute heartbeat.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def heartbeat
  @heartbeat
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def host
  @host
end

#hostsObject

Returns the value of attribute hosts.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def hosts
  @hosts
end

#max_async_publisher_lag_timeObject

Returns the value of attribute max_async_publisher_lag_time.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def max_async_publisher_lag_time
  @max_async_publisher_lag_time
end

#messages_per_batchObject

Returns the value of attribute messages_per_batch.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def messages_per_batch
  @messages_per_batch
end

#network_recovery_intervalObject

Returns the value of attribute network_recovery_interval.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def network_recovery_interval
  @network_recovery_interval
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def password
  @password
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def port
  @port
end

#publisher_confirmsObject

Returns the value of attribute publisher_confirms.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def publisher_confirms
  @publisher_confirms
end

#publisher_confirms_timeoutObject

Returns the value of attribute publisher_confirms_timeout.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def publisher_confirms_timeout
  @publisher_confirms_timeout
end

#publisher_threadsObject

Returns the value of attribute publisher_threads.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def publisher_threads
  @publisher_threads
end

#seconds_to_wait_for_graceful_shutdownObject

Returns the value of attribute seconds_to_wait_for_graceful_shutdown.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def seconds_to_wait_for_graceful_shutdown
  @seconds_to_wait_for_graceful_shutdown
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def timeout
  @timeout
end

#tlsObject

Returns the value of attribute tls.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def tls
  @tls
end

#tls_ca_certificatesObject

Returns the value of attribute tls_ca_certificates.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def tls_ca_certificates
  @tls_ca_certificates
end

#tls_certObject

Returns the value of attribute tls_cert.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def tls_cert
  @tls_cert
end

#tls_keyObject

Returns the value of attribute tls_key.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def tls_key
  @tls_key
end

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def username
  @username
end

#verify_peerObject

Returns the value of attribute verify_peer.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def verify_peer
  @verify_peer
end

#virtual_hostObject

Returns the value of attribute virtual_host.



6
7
8
# File 'lib/active_publisher/configuration.rb', line 6

def virtual_host
  @virtual_host
end

Class Method Details

.configure_from_yaml_and_cli(cli_options = {}, reload = false) ⇒ Object

Class Methods



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_publisher/configuration.rb', line 62

def self.configure_from_yaml_and_cli(cli_options = {}, reload = false)
  CONFIGURATION_MUTEX.synchronize do
    @configure_from_yaml_and_cli = nil if reload
    @configure_from_yaml_and_cli ||= begin
      env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["APP_ENV"] || "development"

      yaml_config = attempt_to_load_yaml_file(env)
      DEFAULTS.each_pair do |key, value|
        exists, setting = fetch_config_value(key, cli_options, yaml_config)
        ::ActivePublisher.configuration.public_send("#{key}=", setting) if exists
      end

      true
    end
  end
end

Instance Method Details

#connection_string=(url) ⇒ Object



123
124
125
126
127
128
# File 'lib/active_publisher/configuration.rb', line 123

def connection_string=(url)
  settings = ::ActionSubscriber::URI.parse_amqp_url(url)
  settings.each do |key, value|
    send("#{key}=", value)
  end
end