jetstream_bridge 4.5.0 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +338 -87
  3. data/README.md +3 -13
  4. data/docs/GETTING_STARTED.md +8 -12
  5. data/docs/PRODUCTION.md +13 -35
  6. data/docs/RESTRICTED_PERMISSIONS.md +525 -0
  7. data/docs/TESTING.md +33 -22
  8. data/lib/generators/jetstream_bridge/health_check/health_check_generator.rb +3 -3
  9. data/lib/generators/jetstream_bridge/initializer/templates/jetstream_bridge.rb +3 -0
  10. data/lib/jetstream_bridge/consumer/consumer.rb +100 -39
  11. data/lib/jetstream_bridge/consumer/message_processor.rb +1 -1
  12. data/lib/jetstream_bridge/consumer/subscription_manager.rb +97 -121
  13. data/lib/jetstream_bridge/core/bridge_helpers.rb +127 -0
  14. data/lib/jetstream_bridge/core/config.rb +32 -161
  15. data/lib/jetstream_bridge/core/connection.rb +508 -0
  16. data/lib/jetstream_bridge/core/connection_factory.rb +95 -0
  17. data/lib/jetstream_bridge/core/debug_helper.rb +2 -9
  18. data/lib/jetstream_bridge/core.rb +2 -0
  19. data/lib/jetstream_bridge/models/subject.rb +15 -23
  20. data/lib/jetstream_bridge/provisioner.rb +67 -0
  21. data/lib/jetstream_bridge/publisher/publisher.rb +121 -92
  22. data/lib/jetstream_bridge/rails/integration.rb +5 -8
  23. data/lib/jetstream_bridge/rails/railtie.rb +3 -4
  24. data/lib/jetstream_bridge/tasks/install.rake +59 -12
  25. data/lib/jetstream_bridge/topology/topology.rb +1 -6
  26. data/lib/jetstream_bridge/version.rb +1 -1
  27. data/lib/jetstream_bridge.rb +345 -202
  28. metadata +8 -8
  29. data/lib/jetstream_bridge/consumer/health_monitor.rb +0 -107
  30. data/lib/jetstream_bridge/core/connection_manager.rb +0 -513
  31. data/lib/jetstream_bridge/core/health_checker.rb +0 -184
  32. data/lib/jetstream_bridge/facade.rb +0 -212
  33. data/lib/jetstream_bridge/publisher/event_envelope_builder.rb +0 -110
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f7e89386a56dac571dddec4c9d5283a975a8354d17d8f953ba148d390d55652
4
- data.tar.gz: 64d5a7ea6bfdf863ea6a24d7d922cfaca565247605860cd999d6c2a8c893f48d
3
+ metadata.gz: '08ea80256539bb801e52672dc900d0e858b4a22fcc76e0958dfa1341e908dcc8'
4
+ data.tar.gz: 6fd4e80d372f8c9c022dfe0992356a73784f517d0a18d78e65ec78a01652443d
5
5
  SHA512:
6
- metadata.gz: c95e0b2a4b829637f6c790cf13e710f814d085298949aadd141220d065cedc47dcd44a46fe8576b0cd280cd343cfd2a959ab4abb842fd0434cb817f9d70f9021
7
- data.tar.gz: ebd5322b78df46177d3395c08674a822fd0cbf2a7111b7fbd7b4405f08ccaa7308d602ed0bcab862f4589730fe3a78c8b611c83d3eb0771eca199da31c0dc118
6
+ metadata.gz: 5b3a853557c531acac60a559673f95e2daab985ec43adf9b711108d2541fef59e109b894e070459a9259a4a3ccceedc15812e1768ce3a41d47b0087ec40a4a65
7
+ data.tar.gz: 76de67fbf04fdc62bab5c952238403a91f430396a20c738d9863aae4dbc2faed364cf9686791ddc566ffb7fb9a82acb2afef780f3dbbcbdb62d9287d6b58fea6
data/CHANGELOG.md CHANGED
@@ -5,185 +5,436 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [4.5.0] - 2026-01-22
9
-
10
- ### Added
11
-
12
- - Dedicated `HealthChecker` service for comprehensive health monitoring
13
- - `ConsumerHealthMonitor` for long-running consumer health tracking
14
- - Stream name configuration now required (no more auto-generated defaults)
15
-
16
- ### Changed
17
-
18
- - Refactored architecture with `Facade` pattern for cleaner API delegation
19
- - Consolidated connection management into `ConnectionManager`
20
- - Extracted health checking logic from connection layer into dedicated service
21
- - Simplified documentation focusing on library features over implementation details
22
-
23
- ### Removed
24
-
25
- - Removed `Connection` (refactored to `ConnectionManager`)
26
- - Removed `BridgeHelpers` module (functionality distributed to appropriate layers)
27
- - Removed auto-generated stream names (explicit configuration required)
28
-
29
8
  ## [4.4.1] - 2026-01-16
30
9
 
31
10
  ### Fixed
32
11
 
33
- - Fixed Rails generator constant qualification to prevent NameError during load
12
+ - **Rails Generators** - Qualify Rails constants to avoid `JetstreamBridge::Rails::Generators` NameError during generator load
34
13
 
35
14
  ## [4.4.0] - 2025-11-24
36
15
 
37
16
  ### Changed
38
17
 
39
- - Enhanced NATS round-trip time measurement with automatic fallback for clients without native `rtt` method
40
- - Improved Rails Rake task detection using `$PROGRAM_NAME` inspection
18
+ - **RTT Measurement** - Enhanced NATS round-trip time measurement with fallback support
19
+ - Added automatic unit normalization (seconds to milliseconds) for RTT values
20
+ - Implemented fallback RTT measurement using `flush` for NATS clients without native `rtt` method
21
+ - Supports both nats-pure and other NATS client implementations
22
+ - Better compatibility across different NATS client versions
23
+
24
+ - **Rails Integration** - Improved Rake task detection reliability
25
+ - Changed from `defined?(::Rake)` check to `$PROGRAM_NAME` inspection
26
+ - More reliable detection of Rake execution context
27
+ - Prevents false positives when Rake is loaded but not executing
41
28
 
42
29
  ### Fixed
43
30
 
44
- - Expanded test coverage for Rails integration and test helpers
31
+ - **Test Coverage** - Comprehensive test suite improvements
32
+ - Added complete test coverage for Rails integration lifecycle methods
33
+ - Added tests for test helper matchers (`have_published`, `be_publish_success`, `be_publish_failure`)
34
+ - Added tests for fixture builders (`sample_event`, `sample_events`, `event`)
35
+ - Added test for RTT fallback behavior when client lacks `rtt` method
36
+ - Added spec file for `bridge_helpers` module
45
37
 
46
38
  ## [4.3.0] - 2025-11-24
47
39
 
48
40
  ### Added
49
41
 
50
- - Exposed reconnection error tracking via `last_reconnect_error` and `last_reconnect_error_at` for better diagnostics
42
+ - **Connection Diagnostics** - Exposed reconnection error tracking for health checks
43
+ - `last_reconnect_error` and `last_reconnect_error_at` now publicly accessible
44
+ - Enables better monitoring and diagnostics of connection issues
45
+ - Added test coverage for diagnostic accessor visibility
51
46
 
52
47
  ### Changed
53
48
 
54
- - Improved topology management during startup and connection initialization
55
- - Rails console now autostarts JetStream Bridge by default (autostart remains disabled for rake tasks)
56
- - Updated documentation to clarify connection initialization behavior
49
+ - **Connection Lifecycle** - Improved topology management during startup
50
+ - `startup!` now explicitly ensures topology is created during initialization
51
+ - `connect_and_ensure_stream!` properly ensures topology after connecting
52
+ - `fetch_stream_info` now ensures connection is established before querying
53
+ - More reliable initialization sequence for non-Rails applications
54
+
55
+ - **Rails Integration** - Changed console autostart behavior
56
+ - Rails console now autostarts JetStream Bridge by default (previously skipped)
57
+ - Simplified autostart logic by removing console detection as skip condition
58
+ - Autostart remains disabled only for rake tasks (unless forced with `JETSTREAM_BRIDGE_FORCE_AUTOSTART`)
59
+ - Better developer experience in Rails console for immediate testing
60
+
61
+ - **Documentation** - Clarified connection initialization behavior
62
+ - Added notes explaining that `configure` only sets options and does not connect
63
+ - Documented when connection actually occurs (Rails: after initialization; non-Rails: call `startup!`)
64
+ - Improved explanation of `lazy_connect` behavior in Rails environments
65
+ - Added guidance for non-Rails applications to call `startup!` explicitly
57
66
 
58
67
  ### Fixed
59
68
 
60
- - Expanded test coverage for topology management and Rails integration
69
+ - **Test Coverage** - Added missing test scenarios
70
+ - Added tests for topology ensuring in `startup!` and `connect_and_ensure_stream!`
71
+ - Added tests for connection initialization in `stream_info`
72
+ - Updated Rails integration specs to reflect new console behavior
61
73
 
62
74
  ## [4.2.0] - 2025-11-24
63
75
 
64
76
  ### Added
65
77
 
66
- - Restructured codebase with `JetstreamBridge::Core` and `JetstreamBridge::Rails` modules
67
- - Enhanced test helpers with fixtures, integration helpers, and RSpec matchers
68
- - New Getting Started guide in `docs/GETTING_STARTED.md`
78
+ - **Modular Code Organization** - Restructured codebase with dedicated modules
79
+ - New `JetstreamBridge::Core` module for core utilities (connection, logging, model utils, helpers)
80
+ - New `JetstreamBridge::Rails` module for Rails-specific integration
81
+ - Improved separation of concerns and code discoverability
82
+ - Better namespace organization for future extensibility
83
+
84
+ - **Enhanced Test Helpers** - Comprehensive testing utilities split into focused modules
85
+ - `JetstreamBridge::TestHelpers::Fixtures` - Convenient fixture generation for events and messages
86
+ - `JetstreamBridge::TestHelpers::IntegrationHelpers` - Full NATS message simulation for integration tests
87
+ - `JetstreamBridge::TestHelpers::Matchers` - RSpec matchers for event publishing assertions
88
+ - Improved test doubles with realistic NATS message structure
89
+ - Better support for testing event-driven Rails applications
90
+
91
+ - **Getting Started Guide** - New comprehensive guide in `docs/GETTING_STARTED.md`
92
+ - Quick installation and setup instructions
93
+ - Publishing and consuming examples
94
+ - Rails integration patterns
95
+ - Links to advanced documentation
69
96
 
70
97
  ### Changed
71
98
 
72
- - Reorganized Rails integration code into dedicated directory structure
73
- - Restructured README for clarity with focus on quick start
74
- - Enhanced gemspec with documentation files
99
+ - **Rails Integration** - Reorganized Rails-specific code
100
+ - Moved from single `lib/jetstream_bridge/railtie.rb` to dedicated `lib/jetstream_bridge/rails/` directory
101
+ - `JetstreamBridge::Rails::Railtie` - Rails lifecycle integration
102
+ - `JetstreamBridge::Rails::Integration` - Autostart logic and Rails environment detection
103
+ - Cleaner separation between gem core and Rails integration
104
+
105
+ - **Documentation** - Restructured README for clarity
106
+ - Condensed README focusing on quick start and highlights
107
+ - Moved detailed guides to dedicated docs directory
108
+ - Improved navigation with links to specialized documentation
109
+ - More concise examples and clearer feature descriptions
110
+
111
+ - **Gemspec** - Enhanced package configuration
112
+ - Added `docs/**/*.md` to distributed files
113
+ - Added `extra_rdoc_files` for better documentation
114
+ - Updated description to emphasize production-readiness
75
115
 
76
116
  ### Fixed
77
117
 
78
- - Resolved all RuboCop style violations
118
+ - **Code Quality** - Resolved all RuboCop style violations
119
+ - Fixed string literal consistency issues
120
+ - Improved code formatting and indentation
121
+ - Reduced complexity in conditional assignments
122
+ - Updated RuboCop configuration for new file structure
79
123
 
80
124
  ## [4.1.0] - 2025-11-23
81
125
 
82
126
  ### Added
83
127
 
84
- - Enhanced subject validation to prevent injection attacks
85
- - Health check rate limiting (1 uncached request per 5 seconds)
86
- - Exponential backoff for consumer reconnection (0.1s to 30s)
87
- - 60-second TTL cache for OverlapGuard stream metadata
88
- - Consumer memory monitoring with automatic health logging
89
- - Production deployment guide in `docs/PRODUCTION.md`
128
+ - **Enhanced Subject Validation** - Strengthened subject component validation for security
129
+ - Validates against control characters, null bytes, tabs, and excessive spaces
130
+ - Enforces maximum subject component length of 255 characters
131
+ - Prevents injection attacks via malformed subject components
132
+ - Provides clear error messages with invalid character details
133
+
134
+ - **Health Check Rate Limiting** - Prevents abuse of health check endpoint
135
+ - Limits uncached health checks to once every 5 seconds per process
136
+ - Cached health checks (30s TTL) bypass rate limit
137
+ - Returns helpful error message with wait time when rate limit exceeded
138
+ - Thread-safe implementation with mutex synchronization
139
+
140
+ - **Consumer Reconnection Backoff** - Exponential backoff for consumer recovery
141
+ - Starts at 0.1s and doubles with each retry up to 30s maximum
142
+ - Resets counter on successful reconnection
143
+ - Logs detailed reconnection attempts with backoff timing
144
+ - Prevents excessive NATS API calls during connection issues
145
+
146
+ - **OverlapGuard Performance Cache** - 60-second TTL cache for stream metadata
147
+ - Reduces N+1 API calls when checking stream overlaps
148
+ - Thread-safe cache implementation with mutex
149
+ - Falls back to cached data on fetch errors
150
+ - Includes `clear_cache!` method for testing
151
+
152
+ - **Consumer Memory Monitoring** - Health checks for long-running consumers
153
+ - Logs health status every 10 minutes (iterations, memory, uptime)
154
+ - Warns when memory usage exceeds 1GB
155
+ - Suggests garbage collection when heap grows large (>100k live objects)
156
+ - Cross-platform memory monitoring (Linux/macOS)
157
+
158
+ - **Production Deployment Guide** - Comprehensive documentation in docs/PRODUCTION.md
159
+ - Database connection pool sizing guidelines
160
+ - NATS HA configuration examples
161
+ - Consumer tuning recommendations
162
+ - Monitoring and alerting best practices
163
+ - Kubernetes deployment examples with health probes
164
+ - Security hardening recommendations
165
+ - Performance optimization techniques
90
166
 
91
167
  ### Changed
92
168
 
93
- - Added `skip_cache` parameter to health check API
169
+ - **Health Check API** - Added optional `skip_cache` parameter
170
+ - `JetstreamBridge.health_check(skip_cache: true)` forces fresh check
171
+ - Default behavior unchanged (uses 30s cache)
172
+ - Rate limited when `skip_cache` is true
94
173
 
95
174
  ### Fixed
96
175
 
97
- - Fixed OverlapGuard test failures with proper cache clearing
176
+ - **Test Suite** - Fixed test failures in OverlapGuard specs
177
+ - Added cache clearing in test setup to prevent interference
178
+ - All 1220 tests passing with 93.32% line coverage
98
179
 
99
180
  ## [4.0.4] - 2025-11-23
100
181
 
101
182
  ### Fixed
102
183
 
103
- - Fixed nats-pure 2.5.0 compatibility with hash-style stream_info responses
184
+ - **NATS Compatibility** - Fix connection failure with nats-pure 2.5.0
185
+ - Handle both object-style and hash-style access for stream_info responses
186
+ - Fixes "undefined method 'streams' for Hash" error during connection establishment
187
+ - Adds compatibility checks using `respond_to?` for config and state attributes
188
+ - Updated 4 files: jetstream_bridge.rb, topology/stream.rb, topology/overlap_guard.rb, debug_helper.rb
189
+ - Maintains backward compatibility with older nats-pure versions
104
190
 
105
191
  ## [4.0.3] - 2025-11-23
106
192
 
107
193
  ### Added
108
194
 
109
- - Comprehensive NATS URL validation on initialization
110
- - Detailed connection lifecycle logging with credential sanitization
195
+ - **Connection Validation** - Comprehensive NATS URL validation on initialization
196
+ - Validates URL format, scheme (nats/nats+tls), host presence, and port range (1-65535)
197
+ - Verifies NATS connection established after connect
198
+ - Verifies JetStream availability with account info check
199
+ - Helpful error messages for common misconfigurations
200
+ - All validation errors include specific guidance for fixes
201
+
202
+ - **Connection Logging** - Detailed logging throughout connection lifecycle
203
+ - Debug logs for URL validation progress and verification steps
204
+ - Info logs for successful validation and JetStream stats (streams, consumers, memory, storage)
205
+ - Error logs for all validation failures with specific details
206
+ - Automatic credential sanitization in all log messages
207
+ - Human-readable resource usage formatting (bytes to KB/MB/GB)
111
208
 
112
209
  ### Fixed
113
210
 
114
- - Fixed health check returning `nil` instead of `false` when disconnected
211
+ - **Health Check** - Fixed `healthy` field returning `nil` instead of `false` when disconnected
212
+ - Changed `stream_info[:exists]` to `stream_info&.fetch(:exists, false)` for proper nil handling
213
+ - Ensures boolean values always returned for monitoring systems
115
214
 
116
215
  ### Changed
117
216
 
118
- - Moved inline RuboCop rules to centralized `.rubocop.yml`
217
+ - **Code Organization** - Moved all inline RuboCop rules to centralized `.rubocop.yml`
218
+ - Removed inline comments from 5 files (logging.rb, model_utils.rb, inbox_event.rb, outbox_event.rb, inbox_message.rb)
219
+ - Added exclusions to `.rubocop.yml` for metrics and naming rules
220
+ - Cleaner codebase with all style exceptions in one location
119
221
 
120
222
  ## [4.0.2] - 2025-11-23
121
223
 
122
224
  ### Fixed
123
225
 
124
- - Prevented retention policy change errors by skipping updates when policy differs
226
+ - **Stream Updates** - Prevent retention policy change errors (NATS error 10052)
227
+ - Skip all stream updates when retention policy differs from expected 'workqueue'
228
+ - Prevents "stream configuration update can not change retention policy to/from workqueue" error
229
+ - Logs warning when stream has mismatched retention policy but skips update
230
+ - Ensures compatibility with existing streams that have different retention policies
125
231
 
126
232
  ## [4.0.1] - 2025-11-23
127
233
 
128
234
  ### Fixed
129
235
 
130
- - Updated version references in documentation
236
+ - **Documentation** - Updated version references in README and YARD documentation
237
+ - Installation instructions now reference version 4.0
238
+ - Health check example output shows correct version
239
+ - YARD documentation reflects current version
131
240
 
132
241
  ## [4.0.0] - 2025-11-23
133
242
 
134
243
  ### Breaking Changes
135
244
 
136
- - Changed DLQ subject pattern from `{env}.sync.dlq` (shared) to `{env}.{app_name}.sync.dlq` (per-app) for better isolation and monitoring
245
+ - **Per-app Dead Letter Queue (DLQ)** - DLQ subject pattern changed for better isolation
246
+ - **Old pattern**: `{env}.sync.dlq` (shared across all apps)
247
+ - **New pattern**: `{env}.{app_name}.sync.dlq` (isolated per app)
248
+ - **Example**: `production.api.sync.dlq` instead of `production.sync.dlq`
249
+
250
+ ### Benefits
251
+
252
+ - **Isolation**: Failed messages from different services don't mix
253
+ - **Easier Monitoring**: Track DLQ metrics per service
254
+ - **Simpler Debugging**: Identify which service is having issues
255
+ - **Independent Processing**: Each team can manage their own DLQ consumer
137
256
 
138
257
  ### Migration Guide
139
258
 
140
- 1. Drain existing DLQ messages from `{env}.sync.dlq`
141
- 2. Deploy update (each app creates its own DLQ subject automatically)
142
- 3. Update monitoring dashboards to track per-app DLQ subjects
143
- 4. Update DLQ consumer configuration
259
+ 1. **Drain existing DLQ**: Process or archive messages from the old shared DLQ (`{env}.sync.dlq`)
260
+ 2. **Deploy update**: Each app will automatically create its own DLQ subject on next deployment
261
+ 3. **Update monitoring**: Adjust dashboards to track per-app DLQ subjects (`{env}.{app_name}.sync.dlq`)
262
+ 4. **Update DLQ consumers**: Update DLQ consumer configuration to use app-specific subjects
144
263
 
145
- ### Changed
264
+ ### Documentation
146
265
 
147
- - Enhanced README with corrected handler signatures and DLQ examples
148
- - Added YARD documentation with 60%+ API coverage
149
- - Achieved RuboCop compliance across entire codebase
266
+ - **Enhanced README** - Comprehensive documentation improvements
267
+ - Fixed consumer handler signature (single `event` parameter, not three)
268
+ - Added complete DLQ consumer examples with Rake task
269
+ - Added thread-safety documentation for Publisher
270
+ - Updated all subject pattern references
271
+ - Added DLQ monitoring examples
272
+ - **YARD documentation** - Professional API documentation
273
+ - Added `.yardopts` configuration for consistent doc generation
274
+ - 60%+ documentation coverage across public APIs
275
+ - Configured RubyDoc.info integration
276
+ - Added Rake tasks for generating docs (`rake yard`)
277
+
278
+ ### Code Quality
279
+
280
+ - **RuboCop compliance** - Zero offenses across entire codebase
281
+ - Configured appropriate exclusions for test files and acceptable patterns
282
+ - Fixed all auto-correctable style violations
283
+ - Added clear comments for non-correctable patterns
150
284
 
151
285
  ## [3.0.0] - 2025-11-23
152
286
 
153
287
  ### Added
154
288
 
155
- - Comprehensive health check API and Rails generator for monitoring endpoints
156
- - Auto-reconnection with exponential backoff and connection state tracking
157
- - Centralized connection factory with thread-safe access
158
- - Well-organized error hierarchy with specific exception classes
159
- - Debug helper utility with configuration and connection diagnostics
160
- - Rake tasks for health checks, validation, and connection testing
161
- - Type-safe value objects (EventEnvelope, Subject)
162
- - Comprehensive test suite with 248+ RSpec tests
163
- - Subject validation to prevent NATS wildcards
289
+ #### Production-Ready Features
290
+
291
+ - **Health checks** - Comprehensive health check API via `JetstreamBridge.health_check`
292
+ - NATS connection status monitoring
293
+ - Stream existence and subject verification
294
+ - Configuration validation
295
+ - Returns structured health data for monitoring systems
296
+ - **Health check generator** - Rails generator for creating health check endpoints
297
+ - `rails g jetstream_bridge:health_check` creates controller and route
298
+ - Automatic route injection into `config/routes.rb`
299
+ - Returns appropriate HTTP status codes (200/503)
300
+ - **Auto-reconnection** - Automatic recovery from connection failures
301
+ - Exponential backoff retry strategy
302
+ - Configurable retry limits and delays
303
+ - Connection state tracking with timestamps
304
+ - **Connection factory** - Centralized connection management
305
+ - Singleton pattern for connection handling
306
+ - Thread-safe connection access
307
+ - Public `connected?` and `connected_at` accessors
308
+
309
+ #### Error Handling
310
+
311
+ - **Comprehensive error hierarchy** - Well-organized exception classes
312
+ - `ConfigurationError` - Base for configuration issues
313
+ - `ConnectionError` - Base for connection problems
314
+ - `PublishError` - Base for publishing failures
315
+ - `ConsumerError` - Base for consumption issues
316
+ - `TopologyError` - Base for stream/subject topology errors
317
+ - `DlqError` - Base for dead-letter queue operations
318
+ - All inherit from `JetstreamBridge::Error`
319
+
320
+ #### Developer Experience
321
+
322
+ - **Debug helper** - Comprehensive debugging utility via `JetstreamBridge::DebugHelper`
323
+ - Configuration dump
324
+ - Connection status
325
+ - Stream information
326
+ - Subject validation
327
+ - Model availability checks
328
+ - **Rake tasks** - CLI tools for operations
329
+ - `rake jetstream_bridge:health` - Check health and connection status
330
+ - `rake jetstream_bridge:validate` - Validate configuration
331
+ - `rake jetstream_bridge:test_connection` - Test NATS connection
332
+ - `rake jetstream_bridge:debug` - Show comprehensive debug information
333
+ - **Value objects** - Type-safe domain models
334
+ - `EventEnvelope` - Structured event representation
335
+ - `Subject` - Subject pattern validation and parsing
336
+
337
+ #### Testing & Quality
338
+
339
+ - **Comprehensive test suite** - 248 RSpec tests covering all core functionality
340
+ - Configuration validation specs
341
+ - Connection factory specs with edge cases (48 new tests added)
342
+ - Server URL normalization (single, comma-separated, arrays, whitespace)
343
+ - Authentication options (user, pass, token)
344
+ - NATS URL validation (nil, empty, whitespace-only)
345
+ - JetStream context creation and nc accessor
346
+ - Event envelope specs with full coverage (18 new tests added)
347
+ - Initialization edge cases (trace ID, Time objects, resource ID extraction)
348
+ - Hash serialization and deserialization
349
+ - Deep immutability validation
350
+ - Equality and hashing behavior
351
+ - Error handling for invalid timestamps
352
+ - Retry strategy specs
353
+ - Model specs
354
+ - Error hierarchy specs
355
+ - **Subject validation** - Prevents NATS wildcards in configuration
356
+ - Validates `env`, `app_name`, and `destination_app` don't contain `.`, `*`, or `>`
357
+ - Clear error messages for invalid subjects
358
+ - **Bug fixes in implementation** - Fixed `EventEnvelope.from_h` to properly handle deserialization
359
+ - Removed invalid `schema_version` parameter
360
+ - Added missing `resource_id` parameter
164
361
 
165
362
  ### Changed
166
363
 
167
- - Consolidated configuration with streamlined Config class
168
- - Enhanced generator templates with better documentation
169
- - Simplified consumer initialization with sensible defaults
170
- - Improved logging with configurable logger and fallbacks
171
- - Switched to Oj for JSON handling performance
172
- - Enhanced topology management with better overlap detection
173
- - Updated README with generators, rake tasks, and operations guide
174
-
175
- ### Fixed
176
-
177
- - Fixed duration parsing for edge cases
178
- - Corrected DLQ subject pattern
179
- - Improved repository transaction safety and locking
180
- - Fixed EventEnvelope deserialization
364
+ #### Architecture Improvements
365
+
366
+ - **Consolidated configuration** - Streamlined `Config` class
367
+ - Removed redundant configuration classes
368
+ - Centralized validation logic
369
+ - Better default values
370
+ - **Enhanced generator templates** - Improved initializer template
371
+ - Better documentation and comments
372
+ - Organized sections (Connection, Consumer, Reliability, Models, Logging)
373
+ - Clear indication of required vs optional settings
374
+ - **Simplified consumer initialization** - Cleaner API
375
+ - Sensible defaults for `durable_name` and `batch_size`
376
+ - Removed unnecessary configuration classes
377
+ - **Better logging** - Configurable logger with sensible defaults
378
+ - Respects `config.logger` setting
379
+ - Falls back to `Rails.logger` in Rails apps
380
+ - Uses `STDOUT` logger otherwise
381
+
382
+ #### Bug Fixes
383
+
384
+ - **Fixed duration parsing** - Correct integer conversion for duration strings
385
+ - Handles edge cases properly
386
+ - Added comprehensive tests
387
+ - **Fixed subject format** - Corrected DLQ subject pattern
388
+ - Changed from `{env}.data.sync.dlq` to `{env}.sync.dlq`
389
+ - Updated all documentation
390
+ - **Repository improvements**
391
+ - Transaction safety for all database operations
392
+ - Pessimistic locking for outbox operations
393
+ - Race condition protection
394
+ - Better error handling and logging
181
395
 
182
396
  ### Refactored
183
397
 
184
- - Consolidated consumer architecture
185
- - Streamlined inbox/outbox model handling
186
- - Removed deprecated code (BackoffStrategy, ConsumerConfig, MessageContext)
398
+ - **Consumer architecture** - Consolidated consumer support classes
399
+ - Merged related functionality
400
+ - Reduced file count
401
+ - Clearer separation of concerns
402
+ - **Model handling** - Streamlined inbox/outbox models
403
+ - Graceful column detection without connection boot
404
+ - Better validation guards
405
+ - Simplified attribute handling
406
+ - **JSON handling** - Switched to Oj for performance
407
+ - Faster JSON parsing/serialization
408
+ - Consistent JSON handling across the gem
409
+ - **Topology management** - Enhanced stream and subject handling
410
+ - Improved overlap detection
411
+ - Better error messages
412
+ - More robust subject matching
413
+
414
+ ### Documentation Updates
415
+
416
+ - **Updated README** - Comprehensive documentation updates
417
+ - Added section for Rails generators and rake tasks
418
+ - Documented all new health check features
419
+ - Fixed incorrect subject patterns
420
+ - Added operations guide
421
+ - Improved getting started section
422
+ - **Enhanced code comments** - Better inline documentation
423
+ - YARD-style documentation for public APIs
424
+ - Clear explanations of complex logic
425
+ - Usage examples in comments
426
+ - **Generator improvements** - Better user guidance
427
+ - Clear success messages
428
+ - Usage instructions after generation
429
+ - Example configurations
430
+
431
+ ### Internal
432
+
433
+ - **Removed deprecated code**
434
+ - Cleaned up unused classes and methods
435
+ - Removed `BackoffStrategy` (consolidated into retry strategy)
436
+ - Removed `ConsumerConfig` (merged into main config)
437
+ - Removed `MessageContext` (functionality integrated)
187
438
 
188
439
  ## [2.10.0] and earlier
189
440
 
data/README.md CHANGED
@@ -34,7 +34,7 @@ Production-ready NATS JetStream bridge for Ruby/Rails with outbox, inbox, DLQ, a
34
34
 
35
35
  ```ruby
36
36
  # Gemfile
37
- gem "jetstream_bridge", "~> 4.0"
37
+ gem "jetstream_bridge", "~> 4.5"
38
38
  ```
39
39
 
40
40
  ```bash
@@ -43,18 +43,7 @@ bin/rails g jetstream_bridge:install
43
43
  bin/rails db:migrate
44
44
  ```
45
45
 
46
- ```ruby
47
- # config/initializers/jetstream_bridge.rb
48
- JetstreamBridge.configure do |config|
49
- config.nats_urls = ENV.fetch("NATS_URLS", "nats://localhost:4222")
50
- config.app_name = "my_app"
51
- config.destination_app = "worker_app"
52
- config.stream_name = "my_app-jetstream-bridge-stream"
53
- config.use_outbox = true
54
- config.use_inbox = true
55
- config.use_dlq = true
56
- end
57
- ```
46
+ The install generator creates the initializer, migrations, and optional health check scaffold. For full configuration options and non-Rails boot flows, see [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md).
58
47
 
59
48
  Publish:
60
49
 
@@ -75,6 +64,7 @@ consumer.run!
75
64
 
76
65
  - [Getting Started](docs/GETTING_STARTED.md)
77
66
  - [Production Guide](docs/PRODUCTION.md)
67
+ - [Restricted Permissions & Provisioning](docs/RESTRICTED_PERMISSIONS.md)
78
68
  - [Testing with Mock NATS](docs/TESTING.md)
79
69
 
80
70
  ## License
@@ -6,7 +6,7 @@ This guide covers installation, Rails setup, configuration, and basic publish/co
6
6
 
7
7
  ```ruby
8
8
  # Gemfile
9
- gem "jetstream_bridge", "~> 4.0"
9
+ gem "jetstream_bridge", "~> 4.5"
10
10
  ```
11
11
 
12
12
  ```bash
@@ -39,9 +39,9 @@ Generators create:
39
39
  # config/initializers/jetstream_bridge.rb
40
40
  JetstreamBridge.configure do |config|
41
41
  config.nats_urls = ENV.fetch("NATS_URLS", "nats://localhost:4222")
42
+ config.stream_name = ENV.fetch("JETSTREAM_STREAM_NAME", "jetstream-bridge-stream")
42
43
  config.app_name = "my_app"
43
44
  config.destination_app = ENV.fetch("DESTINATION_APP")
44
- config.stream_name = "my_app-jetstream-bridge-stream" # required
45
45
 
46
46
  config.use_outbox = true # transactional publish
47
47
  config.use_inbox = true # idempotent consume
@@ -51,19 +51,15 @@ JetstreamBridge.configure do |config|
51
51
  config.max_deliver = 5
52
52
  config.ack_wait = "30s"
53
53
  config.backoff = %w[1s 5s 15s 30s 60s]
54
-
55
- # Optional: Custom inbox prefix if NATS account restricts _INBOX.>
56
- # config.inbox_prefix = "$RPC"
57
-
58
- # Optional: Pre-provisioned stream/consumer names
59
- # config.durable_name = "my-durable"
60
-
61
- # Optional: Disable JetStream management APIs (requires pre-provisioning)
62
- # config.disable_js_api = false
63
54
  end
55
+
56
+ # Note: `configure` only sets options; it does not connect. Rails will start
57
+ # JetstreamBridge after initialization via the Railtie. For non-Rails or custom
58
+ # boot flows, call `JetstreamBridge.startup!` (or rely on auto-connect on first
59
+ # publish/subscribe).
64
60
  ```
65
61
 
66
- Rails starts JetStream Bridge automatically after initialization. For non-Rails apps, call `JetstreamBridge.connect!` or rely on auto-connect on first publish/subscribe.
62
+ Rails autostart runs after initialization (including in console). You can opt out for rake tasks or other tooling with `config.lazy_connect = true` or `JETSTREAM_BRIDGE_DISABLE_AUTOSTART=1`; it will then connect on first publish/subscribe.
67
63
 
68
64
  ## Publish
69
65