Class: ActionSubscriber::Configuration
- Inherits:
-
Object
- Object
- ActionSubscriber::Configuration
- Defined in:
- lib/action_subscriber/configuration.rb
Constant Summary collapse
- CONFIGURATION_MUTEX =
::Mutex.new
- NETWORK_RECOVERY_INTERVAL =
1.freeze
- DEFAULTS =
{ :allow_low_priority_methods => false, :connection_reaping_interval => 6, :connection_reaping_timeout_interval => 5, :default_exchange => 'events', :heartbeat => 5, :host => 'localhost', :hosts => [], :network_recovery_interval => NETWORK_RECOVERY_INTERVAL, :password => "guest", :port => 5672, :prefetch => 2, :resubscribe_on_consumer_cancellation => true, :seconds_to_wait_for_graceful_shutdown => 30, :threadpool_size => 8, :timeout => 1, :tls => false, :tls_ca_certificates => [], :tls_cert => nil, :tls_key => nil, :username => "guest", :verify_peer => true, :virtual_host => "/" }
Instance Attribute Summary collapse
-
#allow_low_priority_methods ⇒ Object
Returns the value of attribute allow_low_priority_methods.
-
#connection_reaping_interval ⇒ Object
Returns the value of attribute connection_reaping_interval.
-
#connection_reaping_timeout_interval ⇒ Object
Returns the value of attribute connection_reaping_timeout_interval.
-
#decoder ⇒ Object
Returns the value of attribute decoder.
-
#default_exchange ⇒ Object
Returns the value of attribute default_exchange.
-
#error_handler ⇒ Object
Returns the value of attribute error_handler.
-
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
-
#host ⇒ Object
Returns the value of attribute host.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#network_recovery_interval ⇒ Object
Returns the value of attribute network_recovery_interval.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#prefetch ⇒ Object
Returns the value of attribute prefetch.
-
#resubscribe_on_consumer_cancellation ⇒ Object
Returns the value of attribute resubscribe_on_consumer_cancellation.
-
#seconds_to_wait_for_graceful_shutdown ⇒ Object
Returns the value of attribute seconds_to_wait_for_graceful_shutdown.
-
#threadpool_size ⇒ Object
Returns the value of attribute threadpool_size.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#tls ⇒ Object
Returns the value of attribute tls.
-
#tls_ca_certificates ⇒ Object
Returns the value of attribute tls_ca_certificates.
-
#tls_cert ⇒ Object
Returns the value of attribute tls_cert.
-
#tls_key ⇒ Object
Returns the value of attribute tls_key.
-
#username ⇒ Object
Returns the value of attribute username.
-
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
-
#virtual_host ⇒ Object
Returns the value of attribute virtual_host.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_decoder(decoders) ⇒ Object
Instance Methods.
- #connection_string=(url) ⇒ Object
-
#initialize ⇒ Configuration
constructor
Instance Methods.
- #inspect ⇒ Object
- #middleware ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Instance Methods
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/action_subscriber/configuration.rb', line 99 def initialize self.decoder = { 'application/json' => lambda { |payload| JSON.parse(payload) }, 'text/plain' => lambda { |payload| payload.dup } } self.error_handler = lambda do |error, env_hash| logger = ::ActionSubscriber::Logging.logger logger.error(error.) logger.error(error.class.to_s) logger.error(error.backtrace.join("\n")) if error.try(:backtrace) && error.backtrace.is_a?(::Array) end DEFAULTS.each_pair do |key, value| self.__send__("#{key}=", value) end end |
Instance Attribute Details
#allow_low_priority_methods ⇒ Object
Returns the value of attribute allow_low_priority_methods.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def allow_low_priority_methods @allow_low_priority_methods end |
#connection_reaping_interval ⇒ Object
Returns the value of attribute connection_reaping_interval.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def connection_reaping_interval @connection_reaping_interval end |
#connection_reaping_timeout_interval ⇒ Object
Returns the value of attribute connection_reaping_timeout_interval.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def connection_reaping_timeout_interval @connection_reaping_timeout_interval end |
#decoder ⇒ Object
Returns the value of attribute decoder.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def decoder @decoder end |
#default_exchange ⇒ Object
Returns the value of attribute default_exchange.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def default_exchange @default_exchange end |
#error_handler ⇒ Object
Returns the value of attribute error_handler.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def error_handler @error_handler end |
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def heartbeat @heartbeat end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def host @host end |
#hosts ⇒ Object
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def hosts @hosts end |
#network_recovery_interval ⇒ Object
Returns the value of attribute network_recovery_interval.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def network_recovery_interval @network_recovery_interval end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def port @port end |
#prefetch ⇒ Object
Returns the value of attribute prefetch.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def prefetch @prefetch end |
#resubscribe_on_consumer_cancellation ⇒ Object
Returns the value of attribute resubscribe_on_consumer_cancellation.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def resubscribe_on_consumer_cancellation @resubscribe_on_consumer_cancellation end |
#seconds_to_wait_for_graceful_shutdown ⇒ Object
Returns the value of attribute seconds_to_wait_for_graceful_shutdown.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def seconds_to_wait_for_graceful_shutdown @seconds_to_wait_for_graceful_shutdown end |
#threadpool_size ⇒ Object
Returns the value of attribute threadpool_size.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def threadpool_size @threadpool_size end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def timeout @timeout end |
#tls ⇒ Object
Returns the value of attribute tls.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def tls @tls end |
#tls_ca_certificates ⇒ Object
Returns the value of attribute tls_ca_certificates.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def tls_ca_certificates @tls_ca_certificates end |
#tls_cert ⇒ Object
Returns the value of attribute tls_cert.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def tls_cert @tls_cert end |
#tls_key ⇒ Object
Returns the value of attribute tls_key.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def tls_key @tls_key end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def username @username end |
#verify_peer ⇒ Object
Returns the value of attribute verify_peer.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def verify_peer @verify_peer end |
#virtual_host ⇒ Object
Returns the value of attribute virtual_host.
6 7 8 |
# File 'lib/action_subscriber/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 78 79 80 81 82 83 84 85 |
# File 'lib/action_subscriber/configuration.rb', line 62 def self.configure_from_yaml_and_cli( = {}, 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 = {} absolute_config_path = ::File.(::File.join("config", "action_subscriber.yml")) if ::File.exists?(absolute_config_path) erb = ::ERB.new(::File.read(absolute_config_path)).result # Defined in Psych 3.2+ and the new canonical way to load trusted documents: # https://github.com/ruby/psych/issues/533#issuecomment-1019363688 yaml_config = ::YAML.unsafe_load(erb)[env] end ::ActionSubscriber::Configuration::DEFAULTS.each_pair do |key, value| exists, setting = fetch_config_value(key, , yaml_config) ::ActionSubscriber.config.__send__("#{key}=", setting) if exists end true end end end |
Instance Method Details
#add_decoder(decoders) ⇒ Object
Instance Methods
121 122 123 124 125 126 127 128 129 |
# File 'lib/action_subscriber/configuration.rb', line 121 def add_decoder(decoders) decoders.each_pair do |content_type, decoder| unless decoder.arity == 1 raise "ActionSubscriber decoders must have an arity of 1. The #{content_type} decoder was given with arity of #{decoder.arity}." end end self.decoder.merge!(decoders) end |
#connection_string=(url) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/action_subscriber/configuration.rb', line 131 def connection_string=(url) settings = ::ActionSubscriber::URI.parse_amqp_url(url) settings.each do |key, value| send("#{key}=", value) end end |
#inspect ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/action_subscriber/configuration.rb', line 147 def inspect inspection_string = <<-INSPECT.strip_heredoc Rabbit Hosts: #{hosts} Rabbit Port: #{port} Threadpool Size: #{threadpool_size} Low Priority Subscriber: #{allow_low_priority_methods} Decoders: INSPECT decoder.each_key { |key| inspection_string << " --#{key}\n" } return inspection_string end |
#middleware ⇒ Object
143 144 145 |
# File 'lib/action_subscriber/configuration.rb', line 143 def middleware @middleware ||= Middleware.initialize_stack end |