Class: JetstreamBridge::Config
- Inherits:
-
Object
- Object
- JetstreamBridge::Config
- Defined in:
- lib/jetstream_bridge/core/config.rb
Overview
Configuration object for JetStream Bridge.
Holds all configuration settings including NATS connection details, application identifiers, reliability features, and consumer tuning.
Defined Under Namespace
Modules: Status
Instance Attribute Summary collapse
-
#ack_wait ⇒ String, Integer
Time to wait for acknowledgment before redelivery.
-
#app_name ⇒ String
Application name for subject routing.
-
#backoff ⇒ Array<String>
Backoff delays between retries.
-
#connect_retry_attempts ⇒ Integer
Number of retry attempts for initial connection.
-
#connect_retry_delay ⇒ Integer
Delay between connection retry attempts (in seconds).
-
#destination_app ⇒ String
NATS server URL(s), comma-separated for multiple servers.
-
#env ⇒ String
Environment namespace (development, staging, production).
-
#inbox_model ⇒ String
ActiveRecord model class name for inbox events.
-
#lazy_connect ⇒ Boolean
Enable lazy connection (connect on first use instead of during configure).
-
#logger ⇒ Logger?
Logger instance.
-
#max_deliver ⇒ Integer
Maximum delivery attempts before moving to DLQ.
-
#nats_urls ⇒ String
NATS server URL(s).
-
#outbox_model ⇒ String
ActiveRecord model class name for outbox events.
-
#preset_applied ⇒ Symbol?
readonly
Applied preset name.
-
#use_dlq ⇒ Boolean
Enable dead letter queue.
-
#use_inbox ⇒ Boolean
Enable idempotent inbox pattern.
-
#use_outbox ⇒ Boolean
Enable transactional outbox pattern.
Instance Method Summary collapse
-
#apply_preset(preset_name) ⇒ self
Apply a configuration preset.
-
#destination_subject ⇒ String
Get the NATS subject this application subscribes to.
-
#dlq_subject ⇒ String
Get the dead letter queue subject for this application.
-
#durable_name ⇒ String
Get the durable consumer name for this application.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#source_subject ⇒ String
Get the NATS subject this application publishes to.
-
#stream_name ⇒ String
Get the JetStream stream name for this environment.
-
#validate! ⇒ true
Validate all configuration settings.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/jetstream_bridge/core/config.rb', line 99 def initialize @nats_urls = ENV['NATS_URLS'] || ENV['NATS_URL'] || 'nats://localhost:4222' @env = ENV['NATS_ENV'] || 'development' @app_name = ENV['APP_NAME'] || 'app' @destination_app = ENV.fetch('DESTINATION_APP', nil) @max_deliver = 5 @ack_wait = '30s' @backoff = %w[1s 5s 15s 30s 60s] @use_outbox = false @use_inbox = false @use_dlq = true @outbox_model = 'JetstreamBridge::OutboxEvent' @inbox_model = 'JetstreamBridge::InboxEvent' @logger = nil @preset_applied = nil # Connection management @connect_retry_attempts = 3 @connect_retry_delay = 2 @lazy_connect = false end |
Instance Attribute Details
#ack_wait ⇒ String, Integer
Time to wait for acknowledgment before redelivery
64 65 66 |
# File 'lib/jetstream_bridge/core/config.rb', line 64 def ack_wait @ack_wait end |
#app_name ⇒ String
Application name for subject routing
58 59 60 |
# File 'lib/jetstream_bridge/core/config.rb', line 58 def app_name @app_name end |
#backoff ⇒ Array<String>
Backoff delays between retries
67 68 69 |
# File 'lib/jetstream_bridge/core/config.rb', line 67 def backoff @backoff end |
#connect_retry_attempts ⇒ Integer
Number of retry attempts for initial connection
91 92 93 |
# File 'lib/jetstream_bridge/core/config.rb', line 91 def connect_retry_attempts @connect_retry_attempts end |
#connect_retry_delay ⇒ Integer
Delay between connection retry attempts (in seconds)
94 95 96 |
# File 'lib/jetstream_bridge/core/config.rb', line 94 def connect_retry_delay @connect_retry_delay end |
#destination_app ⇒ String
NATS server URL(s), comma-separated for multiple servers
49 50 51 |
# File 'lib/jetstream_bridge/core/config.rb', line 49 def destination_app @destination_app end |
#env ⇒ String
Environment namespace (development, staging, production)
55 56 57 |
# File 'lib/jetstream_bridge/core/config.rb', line 55 def env @env end |
#inbox_model ⇒ String
ActiveRecord model class name for inbox events
76 77 78 |
# File 'lib/jetstream_bridge/core/config.rb', line 76 def inbox_model @inbox_model end |
#lazy_connect ⇒ Boolean
Enable lazy connection (connect on first use instead of during configure)
97 98 99 |
# File 'lib/jetstream_bridge/core/config.rb', line 97 def lazy_connect @lazy_connect end |
#logger ⇒ Logger?
Logger instance
85 86 87 |
# File 'lib/jetstream_bridge/core/config.rb', line 85 def logger @logger end |
#max_deliver ⇒ Integer
Maximum delivery attempts before moving to DLQ
61 62 63 |
# File 'lib/jetstream_bridge/core/config.rb', line 61 def max_deliver @max_deliver end |
#nats_urls ⇒ String
NATS server URL(s)
52 53 54 |
# File 'lib/jetstream_bridge/core/config.rb', line 52 def nats_urls @nats_urls end |
#outbox_model ⇒ String
ActiveRecord model class name for outbox events
79 80 81 |
# File 'lib/jetstream_bridge/core/config.rb', line 79 def outbox_model @outbox_model end |
#preset_applied ⇒ Symbol? (readonly)
Applied preset name
88 89 90 |
# File 'lib/jetstream_bridge/core/config.rb', line 88 def preset_applied @preset_applied end |
#use_dlq ⇒ Boolean
Enable dead letter queue
82 83 84 |
# File 'lib/jetstream_bridge/core/config.rb', line 82 def use_dlq @use_dlq end |
#use_inbox ⇒ Boolean
Enable idempotent inbox pattern
73 74 75 |
# File 'lib/jetstream_bridge/core/config.rb', line 73 def use_inbox @use_inbox end |
#use_outbox ⇒ Boolean
Enable transactional outbox pattern
70 71 72 |
# File 'lib/jetstream_bridge/core/config.rb', line 70 def use_outbox @use_outbox end |
Instance Method Details
#apply_preset(preset_name) ⇒ self
Apply a configuration preset
127 128 129 130 131 132 |
# File 'lib/jetstream_bridge/core/config.rb', line 127 def apply_preset(preset_name) require_relative 'config_preset' ConfigPreset.apply(self, preset_name) @preset_applied = preset_name.to_sym self end |
#destination_subject ⇒ String
Get the NATS subject this application subscribes to.
174 175 176 177 178 179 |
# File 'lib/jetstream_bridge/core/config.rb', line 174 def destination_subject validate_subject_component!(env, 'env') validate_subject_component!(app_name, 'app_name') validate_subject_component!(destination_app, 'destination_app') "#{env}.#{destination_app}.sync.#{app_name}" end |
#dlq_subject ⇒ String
Get the dead letter queue subject for this application.
Each app has its own DLQ for better isolation and monitoring.
192 193 194 195 196 |
# File 'lib/jetstream_bridge/core/config.rb', line 192 def dlq_subject validate_subject_component!(env, 'env') validate_subject_component!(app_name, 'app_name') "#{env}.#{app_name}.sync.dlq" end |
#durable_name ⇒ String
Get the durable consumer name for this application.
205 206 207 |
# File 'lib/jetstream_bridge/core/config.rb', line 205 def durable_name "#{env}-#{app_name}-workers" end |
#source_subject ⇒ String
157 158 159 160 161 162 |
# File 'lib/jetstream_bridge/core/config.rb', line 157 def source_subject validate_subject_component!(env, 'env') validate_subject_component!(app_name, 'app_name') validate_subject_component!(destination_app, 'destination_app') "#{env}.#{app_name}.sync.#{destination_app}" end |
#stream_name ⇒ String
Get the JetStream stream name for this environment.
140 141 142 |
# File 'lib/jetstream_bridge/core/config.rb', line 140 def stream_name "#{env}-jetstream-bridge-stream" end |
#validate! ⇒ true
Validate all configuration settings.
Checks that required settings are present and valid. Raises errors for any invalid configuration.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/jetstream_bridge/core/config.rb', line 218 def validate! errors = [] errors << 'destination_app is required' if destination_app.to_s.strip.empty? errors << 'nats_urls is required' if nats_urls.to_s.strip.empty? errors << 'env is required' if env.to_s.strip.empty? errors << 'app_name is required' if app_name.to_s.strip.empty? errors << 'max_deliver must be >= 1' if max_deliver.to_i < 1 errors << 'backoff must be an array' unless backoff.is_a?(Array) errors << 'backoff must not be empty' if backoff.is_a?(Array) && backoff.empty? raise ConfigurationError, "Configuration errors: #{errors.join(', ')}" if errors.any? true end |