Class: KubeMQ::Configuration
- Inherits:
-
Object
- Object
- KubeMQ::Configuration
- Defined in:
- lib/kubemq/configuration.rb
Overview
Central configuration for KubeMQ client connections.
Resolved in precedence order:
- Constructor keyword arguments
- Global configure block
- Environment variables (+KUBEMQ_ADDRESS+,
KUBEMQ_AUTH_TOKEN) - Built-in defaults
Instance Attribute Summary collapse
-
#address ⇒ String
Broker host:port (default:
ENV["KUBEMQ_ADDRESS"]or"localhost:50000"). -
#auth_token ⇒ String?
Bearer authentication token.
-
#client_id ⇒ String
Unique client identifier (default: auto-generated).
-
#default_timeout ⇒ Integer
Default gRPC deadline in seconds (default:
30). -
#keepalive ⇒ KeepAliveConfig
GRPC keepalive settings.
-
#log_level ⇒ Symbol
Log level —
:debug,:info,:warn,:error(default::warn). -
#max_receive_size ⇒ Integer
Maximum inbound message size in bytes (default: 104_857_600 / 100 MB).
-
#max_send_size ⇒ Integer
Maximum outbound message size in bytes (default: 104_857_600 / 100 MB).
-
#reconnect_policy ⇒ ReconnectPolicy
Auto-reconnect policy.
-
#tls ⇒ TLSConfig
TLS/mTLS configuration.
Instance Method Summary collapse
-
#initialize(address: nil, client_id: nil, auth_token: nil, tls: nil, keepalive: nil, reconnect_policy: nil, max_send_size: 104_857_600, max_receive_size: 104_857_600, log_level: :warn, default_timeout: 30) ⇒ Configuration
constructor
Creates a new configuration with the given options.
-
#inspect ⇒ String
Returns a developer-friendly string with the auth token redacted.
-
#validate! ⇒ Boolean
Validates this configuration and raises on invalid settings.
Constructor Details
#initialize(address: nil, client_id: nil, auth_token: nil, tls: nil, keepalive: nil, reconnect_policy: nil, max_send_size: 104_857_600, max_receive_size: 104_857_600, log_level: :warn, default_timeout: 30) ⇒ Configuration
Creates a new configuration with the given options.
Unspecified options fall back to environment variables and then to built-in defaults.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/kubemq/configuration.rb', line 200 def initialize(address: nil, client_id: nil, auth_token: nil, tls: nil, keepalive: nil, reconnect_policy: nil, max_send_size: 104_857_600, max_receive_size: 104_857_600, log_level: :warn, default_timeout: 30) @address = address || ENV.fetch('KUBEMQ_ADDRESS', 'localhost:50000') @client_id = client_id || "kubemq-ruby-#{SecureRandom.hex(4)}" @auth_token = auth_token || ENV.fetch('KUBEMQ_AUTH_TOKEN', nil) @tls = tls || TLSConfig.new @keepalive = keepalive || KeepAliveConfig.new @reconnect_policy = reconnect_policy || ReconnectPolicy.new @max_send_size = max_send_size @max_receive_size = max_receive_size @log_level = log_level @default_timeout = Integer(default_timeout) end |
Instance Attribute Details
#address ⇒ String
Returns broker host:port (default: ENV["KUBEMQ_ADDRESS"] or "localhost:50000").
180 181 182 |
# File 'lib/kubemq/configuration.rb', line 180 def address @address end |
#auth_token ⇒ String?
Returns bearer authentication token.
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#client_id ⇒ String
Returns unique client identifier (default: auto-generated).
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#default_timeout ⇒ Integer
Returns default gRPC deadline in seconds (default: 30).
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#keepalive ⇒ KeepAliveConfig
Returns gRPC keepalive settings.
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#log_level ⇒ Symbol
Returns log level — :debug, :info, :warn, :error (default: :warn).
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#max_receive_size ⇒ Integer
Returns maximum inbound message size in bytes (default: 104_857_600 / 100 MB).
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#max_send_size ⇒ Integer
Returns maximum outbound message size in bytes (default: 104_857_600 / 100 MB).
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#reconnect_policy ⇒ ReconnectPolicy
Returns auto-reconnect policy.
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
#tls ⇒ TLSConfig
Returns TLS/mTLS configuration.
180 181 182 183 |
# File 'lib/kubemq/configuration.rb', line 180 attr_accessor :address, :client_id, :auth_token, :tls, :keepalive, :reconnect_policy, :max_send_size, :max_receive_size, :log_level, :default_timeout |
Instance Method Details
#inspect ⇒ String
Returns a developer-friendly string with the auth token redacted.
219 220 221 222 |
# File 'lib/kubemq/configuration.rb', line 219 def inspect token_display = @auth_token ? '[REDACTED]' : 'nil' "#<#{self.class} address=#{@address.inspect} client_id=#{@client_id.inspect} auth_token=#{token_display}>" end |
#validate! ⇒ Boolean
Validates this configuration and raises on invalid settings.
Checks that address is present and that TLS cert/key files are
provided as a pair when TLS is enabled.
rubocop:disable Naming/PredicateMethod -- bang API: raises on invalid config or returns true
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/kubemq/configuration.rb', line 234 def validate! raise ConfigurationError, 'address is required' if @address.nil? || @address.empty? if @tls.enabled && @tls.cert_file && !@tls.key_file raise ConfigurationError, 'TLS key_file is required when cert_file is set' end if @tls.enabled && @tls.key_file && !@tls.cert_file raise ConfigurationError, 'TLS cert_file is required when key_file is set' end true end |