smart_message 0.0.12 → 0.0.13

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -1
  3. data/Gemfile.lock +5 -5
  4. data/docs/core-concepts/architecture.md +5 -10
  5. data/docs/getting-started/examples.md +0 -12
  6. data/docs/getting-started/quick-start.md +4 -9
  7. data/docs/index.md +4 -4
  8. data/docs/reference/serializers.md +160 -488
  9. data/docs/reference/transports.md +1 -125
  10. data/docs/transports/redis-transport-comparison.md +215 -350
  11. data/docs/transports/redis-transport.md +3 -22
  12. data/examples/README.md +6 -9
  13. data/examples/city_scenario/README.md +1 -1
  14. data/examples/city_scenario/messages/emergency_911_message.rb +0 -1
  15. data/examples/city_scenario/messages/emergency_resolved_message.rb +0 -1
  16. data/examples/city_scenario/messages/fire_dispatch_message.rb +0 -1
  17. data/examples/city_scenario/messages/fire_emergency_message.rb +0 -1
  18. data/examples/city_scenario/messages/health_check_message.rb +0 -1
  19. data/examples/city_scenario/messages/health_status_message.rb +0 -1
  20. data/examples/city_scenario/messages/police_dispatch_message.rb +0 -1
  21. data/examples/city_scenario/messages/silent_alarm_message.rb +0 -1
  22. data/examples/memory/01_message_deduplication_demo.rb +0 -2
  23. data/examples/memory/02_dead_letter_queue_demo.rb +0 -3
  24. data/examples/memory/03_point_to_point_orders.rb +0 -2
  25. data/examples/memory/04_publish_subscribe_events.rb +0 -1
  26. data/examples/memory/05_many_to_many_chat.rb +0 -3
  27. data/examples/memory/07_proc_handlers_demo.rb +0 -1
  28. data/examples/memory/08_custom_logger_demo.rb +0 -4
  29. data/examples/memory/09_error_handling_demo.rb +0 -3
  30. data/examples/memory/10_entity_addressing_basic.rb +0 -6
  31. data/examples/memory/11_entity_addressing_with_filtering.rb +0 -4
  32. data/examples/memory/12_regex_filtering_microservices.rb +0 -1
  33. data/examples/memory/13_header_block_configuration.rb +0 -5
  34. data/examples/memory/14_global_configuration_demo.rb +0 -2
  35. data/examples/memory/15_logger_demo.rb +0 -1
  36. data/examples/memory/README.md +3 -3
  37. data/examples/redis/01_smart_home_iot_demo.rb +0 -4
  38. data/examples/redis/README.md +0 -2
  39. data/lib/smart_message/base.rb +19 -10
  40. data/lib/smart_message/configuration.rb +2 -23
  41. data/lib/smart_message/dead_letter_queue.rb +1 -1
  42. data/lib/smart_message/messaging.rb +3 -62
  43. data/lib/smart_message/plugins.rb +1 -42
  44. data/lib/smart_message/transport/base.rb +42 -8
  45. data/lib/smart_message/transport/memory_transport.rb +23 -4
  46. data/lib/smart_message/transport/redis_transport.rb +11 -0
  47. data/lib/smart_message/transport/registry.rb +0 -1
  48. data/lib/smart_message/transport/stdout_transport.rb +28 -10
  49. data/lib/smart_message/transport.rb +0 -1
  50. data/lib/smart_message/version.rb +1 -1
  51. metadata +2 -28
  52. data/docs/guides/redis-queue-getting-started.md +0 -697
  53. data/docs/guides/redis-queue-patterns.md +0 -889
  54. data/docs/guides/redis-queue-production.md +0 -1091
  55. data/docs/transports/redis-enhanced-transport.md +0 -524
  56. data/docs/transports/redis-queue-transport.md +0 -1304
  57. data/examples/redis_enhanced/README.md +0 -319
  58. data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +0 -233
  59. data/examples/redis_enhanced/enhanced_02_fluent_api.rb +0 -331
  60. data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +0 -281
  61. data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +0 -419
  62. data/examples/redis_queue/01_basic_messaging.rb +0 -221
  63. data/examples/redis_queue/01_comprehensive_examples.rb +0 -508
  64. data/examples/redis_queue/02_pattern_routing.rb +0 -405
  65. data/examples/redis_queue/03_fluent_api.rb +0 -422
  66. data/examples/redis_queue/04_load_balancing.rb +0 -486
  67. data/examples/redis_queue/05_microservices.rb +0 -735
  68. data/examples/redis_queue/06_emergency_alerts.rb +0 -777
  69. data/examples/redis_queue/07_queue_management.rb +0 -587
  70. data/examples/redis_queue/README.md +0 -366
  71. data/examples/redis_queue/enhanced_01_basic_patterns.rb +0 -233
  72. data/examples/redis_queue/enhanced_02_fluent_api.rb +0 -331
  73. data/examples/redis_queue/enhanced_03_dual_publishing.rb +0 -281
  74. data/examples/redis_queue/enhanced_04_advanced_routing.rb +0 -419
  75. data/examples/redis_queue/redis_queue_architecture.svg +0 -148
  76. data/lib/smart_message/transport/redis_enhanced_transport.rb +0 -399
  77. data/lib/smart_message/transport/redis_queue_transport.rb +0 -555
@@ -1,496 +1,361 @@
1
- # Redis Transport Comparison
1
+ # Transport Comparison
2
2
 
3
- SmartMessage provides three distinct Redis-based transports, each designed for different use cases and requirements. This document provides a comprehensive comparison to help you choose the right transport for your application.
3
+ SmartMessage provides multiple transport layers, each designed for different use cases and requirements. This document provides a comprehensive comparison to help you choose the right transport for your application.
4
4
 
5
5
  ## Transport Overview
6
6
 
7
7
  | Transport | Type | Best For | Key Feature |
8
8
  |-----------|------|----------|-------------|
9
- | **Redis** | Basic Pub/Sub | Simple scenarios, legacy compatibility | Lightweight, direct Redis pub/sub |
10
- | **Redis Enhanced** | Smart Routing | Microservices, pattern-based routing | RabbitMQ-style patterns with backwards compatibility |
11
- | **Redis Queue** | Persistent Queues | Production systems, load balancing | FIFO queues with consumer groups |
12
-
13
- ![Transport Comparison Matrix](../assets/images/transport-comparison-matrix.svg)
9
+ | **Memory** | In-Memory Queue | Testing, development | No external dependencies, fast |
10
+ | **STDOUT** | Logging/Debug | Development, debugging | Human-readable output |
11
+ | **Redis** | Pub/Sub | Production messaging | Distributed, persistent connections |
14
12
 
15
13
  ---
16
14
 
17
- ## 🔧 Redis Transport (Basic)
15
+ ## 🧠 Memory Transport
18
16
 
19
- The foundational Redis transport using native pub/sub channels.
17
+ Perfect for development, testing, and in-memory message queuing.
20
18
 
21
19
  ### Architecture
22
20
  ```
23
- Publisher → Redis Channel → Subscriber
24
- (direct pub/sub) (thread-based)
21
+ Publisher → Memory Queue → Subscriber
22
+ (thread-safe) (auto-processing)
25
23
  ```
26
24
 
27
- ![Redis Basic Architecture](../assets/images/redis-basic-architecture.svg)
28
-
29
25
  ### Key Characteristics
30
- - **Channel Naming**: Uses message class name directly (`OrderMessage`)
31
- - **Pattern Support**: None - exact channel name matching only
32
- - **Message Persistence**: No - fire-and-forget pub/sub
26
+ - **Message Persistence**: In-memory only - lost on restart
27
+ - **Pattern Support**: None - direct message class routing
33
28
  - **Load Balancing**: No - all subscribers receive all messages
34
- - **Threading**: Traditional thread-per-subscriber model
35
- - **Backwards Compatibility**: Original SmartMessage Redis implementation
29
+ - **Threading**: Thread-safe with mutex protection
30
+ - **External Dependencies**: None
36
31
 
37
32
  ### Configuration
38
33
  ```ruby
39
- SmartMessage::Transport.create(:redis,
40
- url: 'redis://localhost:6379',
41
- db: 0,
42
- auto_subscribe: true,
43
- reconnect_attempts: 5,
44
- reconnect_delay: 1
34
+ SmartMessage::Transport.create(:memory,
35
+ auto_process: true, # Automatically route messages to dispatcher
36
+ max_messages: 1000 # Maximum messages to store in memory
45
37
  )
46
38
  ```
47
39
 
48
40
  ### Use Cases
49
- - **Simple applications** with basic pub/sub needs
50
- - **Development/testing** environments
51
- - **Legacy systems** already using basic Redis transport
52
- - **Scenarios** where message loss is acceptable
53
- - **High-performance** applications needing minimal overhead
41
+ - **Unit testing** - Predictable, isolated environment
42
+ - **Development** - Quick setup without external services
43
+ - **In-memory queuing** - Fast processing without persistence
44
+ - **Message inspection** - Easy access to all stored messages
54
45
 
55
46
  ### Pros
56
- - ✅ Simplest implementation and configuration
57
- - ✅ Lowest resource overhead
58
- - ✅ Direct Redis pub/sub - maximum performance
59
- - ✅ No external dependencies beyond Redis
60
- - ✅ Battle-tested and stable
47
+ - ✅ No external dependencies
48
+ - ✅ Fastest performance (no serialization)
49
+ - ✅ Thread-safe operations
50
+ - ✅ Message inspection capabilities
51
+ - ✅ Memory overflow protection
61
52
 
62
53
  ### Cons
63
- - ❌ No pattern-based routing
64
- - ❌ No message persistence
65
- - ❌ No load balancing capabilities
66
- - ❌ Limited routing intelligence
67
- - ❌ All-or-nothing message delivery
54
+ - ❌ Messages lost on restart
55
+ - ❌ Single-process only
56
+ - ❌ Memory usage grows with message volume
57
+ - ❌ No network distribution
68
58
 
69
59
  ### Example
70
60
  ```ruby
71
- class OrderMessage < SmartMessage::Base
72
- transport SmartMessage::Transport.create(:redis,
73
- url: 'redis://localhost:6379'
74
- )
61
+ class TestMessage < SmartMessage::Base
62
+ property :data
75
63
 
76
- property :order_id
77
- property :amount
64
+ config do
65
+ transport SmartMessage::Transport.create(:memory, auto_process: true)
66
+ end
67
+
68
+ def self.process(decoded_message)
69
+ puts "Processing: #{decoded_message.data}"
70
+ end
78
71
  end
79
72
 
80
- # Publishes to Redis channel "OrderMessage"
81
- OrderMessage.new(order_id: "123", amount: 99.99).publish
82
-
83
- # Subscribes to Redis channel "OrderMessage"
84
- OrderMessage.subscribe
73
+ TestMessage.subscribe
74
+ TestMessage.new(data: "Hello World").publish
85
75
  ```
86
76
 
87
77
  ---
88
78
 
89
- ## 🎯 Redis Enhanced Transport
79
+ ## 📄 STDOUT Transport
90
80
 
91
- Advanced Redis transport with intelligent routing and pattern matching.
81
+ Ideal for development, debugging, and logging scenarios.
92
82
 
93
83
  ### Architecture
94
84
  ```
95
- Publisher → Enhanced RouterDual ChannelsPattern Matcher → Subscriber
96
- (3-part naming) (orig + enhanced) (wildcard support) (thread-based)
85
+ Publisher → Console/File OutputOptional Loopback → Subscriber
86
+ (JSON formatting) (if enabled) (local processing)
97
87
  ```
98
88
 
99
- ![Redis Enhanced Architecture](../assets/images/redis-enhanced-architecture.svg)
100
-
101
89
  ### Key Characteristics
102
- - **Channel Naming**: Dual format - both `MessageClass` and `messagetype.from.to`
103
- - **Pattern Support**: Full wildcard support (`*` single segment, multiple patterns)
104
- - **Message Persistence**: No - still based on pub/sub
105
- - **Load Balancing**: No - all matching subscribers receive messages
106
- - **Threading**: Traditional thread-per-subscriber model
107
- - **Backwards Compatibility**: Yes - publishes to both channel formats
90
+ - **Message Persistence**: File-based if output specified
91
+ - **Pattern Support**: None - logging/debugging focused
92
+ - **Load Balancing**: No - single output destination
93
+ - **Threading**: Thread-safe file operations
94
+ - **External Dependencies**: None
108
95
 
109
96
  ### Configuration
110
97
  ```ruby
111
- SmartMessage::Transport::RedisEnhancedTransport.new(
112
- url: 'redis://localhost:6379',
113
- db: 0,
114
- auto_subscribe: true
98
+ SmartMessage::Transport.create(:stdout,
99
+ loopback: true, # Process messages locally
100
+ output: "messages.log" # Output to file instead of console
115
101
  )
116
102
  ```
117
103
 
118
- ### Enhanced Features
119
-
120
- #### Pattern Subscriptions
121
- ```ruby
122
- transport.subscribe_pattern("ordermessage.*.*") # All order messages
123
- transport.subscribe_pattern("*.payment_service.*") # All to payment service
124
- transport.subscribe_pattern("alertmessage.*.*") # All alerts
125
- ```
126
-
127
- #### Convenience Methods
128
- ```ruby
129
- transport.subscribe_to_recipient('payment-service') # *.*.payment-service
130
- transport.subscribe_from_sender('api-gateway') # *.api-gateway.*
131
- transport.subscribe_to_type('OrderMessage') # ordermessage.*.*
132
- transport.subscribe_to_alerts # emergency.*.*, *alert*.*.*
133
- transport.subscribe_to_broadcasts # *.*.broadcast
134
- ```
135
-
136
- #### Fluent API
137
- ```ruby
138
- transport.where.from('web-app').to('user-service').subscribe
139
- transport.where.type('OrderMessage').from('api').subscribe
140
- transport.where.from('monitoring').to('admin').type('AlertMessage').subscribe
141
- ```
142
-
143
- ![Fluent API Demo](../assets/images/fluent-api-demo.svg)
144
-
145
104
  ### Use Cases
146
- - **Microservices architectures** requiring sophisticated routing
147
- - **Migration scenarios** from basic Redis transport
148
- - **Development environments** needing flexible routing
149
- - **Pattern-based filtering** without message persistence requirements
150
- - **Service-to-service communication** with routing intelligence
105
+ - **Development debugging** - See messages in real-time
106
+ - **Application logging** - Structured message logging
107
+ - **Message tracing** - Track message flow through system
108
+ - **Integration testing** - Verify message content
151
109
 
152
110
  ### Pros
153
- - ✅ Advanced pattern-based routing
154
- - ✅ Fluent, readable subscription API
155
- - ✅ Backwards compatible with basic Redis transport
156
- - ✅ Sophisticated filtering capabilities
157
- - ✅ Service-oriented routing patterns
158
- - ✅ RabbitMQ-style routing without RabbitMQ
111
+ - ✅ Human-readable JSON output
112
+ - ✅ File-based persistence option
113
+ - ✅ Optional loopback for testing
114
+ - ✅ No external dependencies
115
+ - ✅ Structured message formatting
159
116
 
160
117
  ### Cons
161
- - ❌ No message persistence
162
- - ❌ No load balancing
163
- - ❌ Pattern matching overhead (client-side)
164
- - ❌ Dual publishing increases Redis traffic
165
- - ❌ More complex configuration
118
+ - ❌ Not suitable for production messaging
119
+ - ❌ Single output destination
120
+ - ❌ No network distribution
121
+ - ❌ Limited throughput for high-volume scenarios
166
122
 
167
123
  ### Example
168
124
  ```ruby
169
- class OrderMessage < SmartMessage::Base
170
- from 'e-commerce-api'
171
- to 'order-processor'
172
-
173
- transport SmartMessage::Transport::RedisEnhancedTransport.new(
174
- url: 'redis://localhost:6379'
175
- )
125
+ class LogMessage < SmartMessage::Base
126
+ property :level
127
+ property :message
128
+ property :timestamp, default: -> { Time.now.iso8601 }
176
129
 
177
- property :order_id
178
- property :amount
130
+ config do
131
+ transport SmartMessage::Transport.create(:stdout,
132
+ output: "app.log",
133
+ loopback: false
134
+ )
135
+ end
179
136
  end
180
137
 
181
- # Publishes to BOTH:
182
- # - "OrderMessage" (backwards compatibility)
183
- # - "ordermessage.e_commerce_api.order_processor" (enhanced)
184
- OrderMessage.new(order_id: "123", amount: 99.99).publish
185
-
186
- # Pattern-based subscriptions
187
- transport.where.from('e-commerce-api').subscribe
188
- transport.subscribe_to_type('OrderMessage')
138
+ LogMessage.new(level: "INFO", message: "Application started").publish
189
139
  ```
190
140
 
191
141
  ---
192
142
 
193
- ## 🚀 Redis Queue Transport
143
+ ## 🔴 Redis Transport
194
144
 
195
- Production-grade transport with persistent queues and load balancing.
145
+ Production-ready Redis pub/sub transport for distributed messaging.
196
146
 
197
147
  ### Architecture
198
148
  ```
199
- Publisher → Routing Engine → Redis ListConsumer Group → Async Worker
200
- (in-memory) (LPUSH/BRPOP) (load balancing) (fiber-based)
149
+ Publisher → Redis ChannelSubscriber
150
+ (pub/sub) (thread-based)
201
151
  ```
202
152
 
203
- ![Redis Queue Architecture](../assets/images/redis-queue-architecture.svg)
204
-
205
153
  ### Key Characteristics
206
- - **Channel Naming**: Enhanced routing keys with queue-based delivery
207
- - **Pattern Support**: RabbitMQ-compatible wildcard patterns
208
- - **Message Persistence**: Yes - Redis Lists provide FIFO persistence
209
- - **Load Balancing**: Yes - consumer groups distribute messages
210
- - **Threading**: Async/fiber-based for massive concurrency
211
- - **Backwards Compatibility**: No - completely different architecture
154
+ - **Message Persistence**: No - fire-and-forget pub/sub
155
+ - **Pattern Support**: None - exact channel name matching
156
+ - **Load Balancing**: No - all subscribers receive all messages
157
+ - **Threading**: Traditional thread-per-subscriber model
158
+ - **External Dependencies**: Redis server
212
159
 
213
160
  ### Configuration
214
161
  ```ruby
215
- SmartMessage.configure do |config|
216
- config.transport = :redis_queue
217
- config.transport_options = {
218
- url: 'redis://localhost:6379',
219
- db: 0,
220
- queue_prefix: 'smart_message.queue',
221
- exchange_name: 'smart_message',
222
- consumer_group: 'workers',
223
- consumer_id: SecureRandom.hex(4),
224
- consumer_timeout: 1,
225
- auto_subscribe: true
226
- }
227
- end
228
- ```
229
-
230
- ### Advanced Features
231
-
232
- #### Load Balancing
233
- ```ruby
234
- # Multiple consumers share work
235
- consumer_1 = RedisQueueTransport.new(consumer_group: 'workers', consumer_id: 'worker_1')
236
- consumer_2 = RedisQueueTransport.new(consumer_group: 'workers', consumer_id: 'worker_2')
237
- # Messages distributed between worker_1 and worker_2
238
- ```
239
-
240
- #### Pattern-based Routing
241
- ```ruby
242
- transport.subscribe_pattern("#.*.payment_service") # RabbitMQ syntax
243
- transport.subscribe_pattern("order.#.*.*") # Multi-segment wildcards
244
- transport.where().from('api').to('db').subscribe # Fluent API
245
- ```
246
-
247
- #### Queue Management
248
- ```ruby
249
- transport.queue_stats # Queue lengths and info
250
- transport.routing_table # Active pattern mappings
251
- transport.where.from('api').build # Preview pattern without subscribing
162
+ SmartMessage::Transport.create(:redis,
163
+ url: 'redis://localhost:6379', # Redis connection URL
164
+ db: 0, # Redis database number
165
+ auto_subscribe: true, # Automatically start subscriber
166
+ reconnect_attempts: 5, # Connection retry attempts
167
+ reconnect_delay: 1 # Delay between retries (seconds)
168
+ )
252
169
  ```
253
170
 
254
- ### Performance Characteristics
255
-
256
- | Metric | Value | Comparison |
257
- |--------|--------|------------|
258
- | **Latency** | ~0.5ms | 10x faster than RabbitMQ |
259
- | **Throughput** | 100K+ msg/sec | 3-5x faster than RabbitMQ |
260
- | **Concurrent Consumers** | 1000+ | 10x more than traditional threading |
261
- | **Memory per Consumer** | ~2KB | 1000x less than RabbitMQ connections |
262
-
263
171
  ### Use Cases
264
- - **Production systems** requiring message persistence
265
- - **Load-balanced processing** with multiple consumers
266
- - **High-throughput applications** needing maximum performance
267
- - **Fault-tolerant systems** where message loss is unacceptable
268
- - **Enterprise applications** requiring queue monitoring
172
+ - **Production messaging** - Reliable distributed messaging
173
+ - **Microservices communication** - Service-to-service messaging
174
+ - **Real-time applications** - Low-latency message delivery
175
+ - **Scalable architectures** - Multiple publishers and subscribers
269
176
 
270
177
  ### Pros
271
- - ✅ Message persistence and reliability
272
- - ✅ Load balancing and horizontal scaling
273
- - ✅ Exceptional performance (10x faster than RabbitMQ)
274
- - ✅ RabbitMQ-compatible routing patterns
275
- - ✅ Async/fiber concurrency for massive scale
276
- - ✅ Comprehensive queue management and monitoring
277
- - ✅ Consumer groups and fault tolerance
178
+ - ✅ Production-ready reliability
179
+ - ✅ Distributed messaging support
180
+ - ✅ Automatic reconnection handling
181
+ - ✅ Low latency (~1ms)
182
+ - ✅ High throughput (80K+ messages/second)
183
+ - ✅ Automatic serialization (MessagePack/JSON)
278
184
 
279
185
  ### Cons
280
- - ❌ More complex setup and configuration
281
- - ❌ No backwards compatibility with pub/sub transports
282
- - ❌ Requires understanding of async/fiber concepts
283
- - ❌ Additional memory overhead for queue management
284
- - ❌ Client-side pattern matching overhead
186
+ - ❌ Requires Redis server
187
+ - ❌ No message persistence
188
+ - ❌ No pattern-based routing
189
+ - ❌ No load balancing
190
+ - ❌ All subscribers receive all messages
285
191
 
286
192
  ### Example
287
193
  ```ruby
288
194
  class OrderMessage < SmartMessage::Base
289
- from 'e-commerce-api'
290
- to 'order-processor'
291
-
292
- transport :redis_queue # Uses global configuration
293
-
294
195
  property :order_id
196
+ property :customer_id
295
197
  property :amount
296
198
 
297
- def self.process(wrapper)
298
- header, payload = wrapper.split
299
- order_data = JSON.parse(payload)
300
- # Process order with guaranteed delivery
199
+ config do
200
+ transport SmartMessage::Transport.create(:redis,
201
+ url: ENV['REDIS_URL'] || 'redis://localhost:6379',
202
+ db: 1
203
+ )
204
+ end
205
+
206
+ def self.process(decoded_message)
207
+ order = decoded_message
208
+ puts "Processing order #{order.order_id} for $#{order.amount}"
301
209
  end
302
210
  end
303
211
 
304
- # Messages persist in Redis Lists until consumed
305
- OrderMessage.new(order_id: "123", amount: 99.99).publish
306
-
307
- # Load-balanced consumption across consumer group
308
212
  OrderMessage.subscribe
213
+ OrderMessage.new(
214
+ order_id: "ORD-123",
215
+ customer_id: "CUST-456",
216
+ amount: 99.99
217
+ ).publish
309
218
  ```
310
219
 
311
220
  ---
312
221
 
313
222
  ## 📊 Feature Comparison Matrix
314
223
 
315
- | Feature | Basic Redis | Enhanced Redis | Redis Queue |
316
- |---------|------------|----------------|-------------|
317
- | **Message Persistence** | ❌ No | No | Yes |
318
- | **Pattern Matching** | ❌ No | Wildcards | ✅ RabbitMQ-style |
319
- | **Load Balancing** | ❌ No | ❌ No | ✅ Consumer Groups |
320
- | **Backwards Compatibility** | N/A | Dual Publishing | ❌ No |
321
- | **Fluent API** | ❌ No | Yes | Yes |
322
- | **Performance (Latency)** | ~1ms | ~1.2ms | ~0.5ms |
323
- | **Performance (Throughput)** | High | High | Highest |
324
- | **Concurrent Consumers** | ~100s | ~100s | ~1000s |
325
- | **Memory Overhead** | Low | Medium | Medium-High |
326
- | **Setup Complexity** | Low | Medium | High |
327
- | **Learning Curve** | Easy | Medium | Challenging |
328
- | **Production Ready** | Yes | Yes | ✅ Yes |
329
- | **Message Ordering** | No guarantees | No guarantees | ✅ FIFO |
330
- | **Dead Letter Queues** | ❌ No | ❌ No | ✅ Yes |
331
- | **Message TTL** | ❌ No | ❌ No | ✅ Yes |
332
- | **Consumer Acknowledgments** | ❌ No | ❌ No | ✅ Yes |
333
- | **Monitoring/Metrics** | Basic | Basic | ✅ Comprehensive |
224
+ | Feature | Memory | STDOUT | Redis |
225
+ |---------|--------|--------|-------|
226
+ | **Message Persistence** | ❌ Memory Only | File Optional | No |
227
+ | **Network Distribution** | ❌ No | No | ✅ Yes |
228
+ | **External Dependencies** | ❌ None | ❌ None | ✅ Redis |
229
+ | **Pattern Matching** | No | No | ❌ No |
230
+ | **Load Balancing** | ❌ No | No | No |
231
+ | **Setup Complexity** | Easy | Easy | Medium |
232
+ | **Performance (Latency)** | ~0.1ms | ~1ms | ~1ms |
233
+ | **Performance (Throughput)** | Highest | Medium | High |
234
+ | **Serialization** | None | JSON | MessagePack/JSON |
235
+ | **Thread Safety** | Yes | Yes | Yes |
236
+ | **Message Inspection** | Yes | Yes | No |
237
+ | **Production Ready** | Testing Only | Logging Only | ✅ Yes |
238
+ | **Horizontal Scaling** | No | No | ✅ Yes |
334
239
 
335
240
  ---
336
241
 
337
242
  ## 🎯 Choosing the Right Transport
338
243
 
339
- ### Use Basic Redis When:
340
- - ✅ You have simple pub/sub requirements
341
- - ✅ Message loss is acceptable
342
- - ✅ You need minimal setup and configuration
343
- - ✅ You're migrating from existing basic Redis pub/sub
344
- - ✅ Performance and simplicity are top priorities
345
- - ✅ You don't need sophisticated routing
346
-
347
- ### Use Enhanced Redis When:
348
- - ✅ You need RabbitMQ-style routing without RabbitMQ
349
- - ✅ You have microservices requiring intelligent routing
350
- - ✅ You want backwards compatibility with basic Redis
351
- - ✅ You need pattern-based message filtering
352
- - ✅ Message persistence is not critical
353
- - You want a fluent, readable subscription API
354
-
355
- ### Use Redis Queue When:
356
- - ✅ You need message persistence and reliability
357
- - ✅ You require load balancing across multiple consumers
358
- - ✅ You're building production systems with high throughput
359
- - ✅ You need enterprise features (DLQ, monitoring, etc.)
360
- - ✅ You can leverage async/fiber concurrency
361
- - ✅ You want RabbitMQ features with Redis performance
244
+ ### Use Memory Transport When:
245
+ - ✅ You're writing unit tests
246
+ - ✅ You're developing locally
247
+ - ✅ You need fast, in-memory message processing
248
+ - ✅ You want to inspect messages for testing
249
+ - ✅ You don't need persistence or distribution
250
+
251
+ ### Use STDOUT Transport When:
252
+ - You're debugging message flow
253
+ - ✅ You need human-readable message logging
254
+ - ✅ You're building development tools
255
+ - ✅ You want to trace messages in integration tests
256
+ - ✅ You need simple file-based message storage
257
+
258
+ ### Use Redis Transport When:
259
+ - ✅ You're building production applications
260
+ - You need distributed messaging
261
+ - ✅ You have microservices that need to communicate
262
+ - ✅ You need reliable, scalable messaging
263
+ - ✅ You can manage a Redis server dependency
362
264
 
363
265
  ---
364
266
 
365
- ## 🔄 Migration Paths
267
+ ## 🔄 Migration Patterns
366
268
 
367
- ### From Basic Enhanced
269
+ ### DevelopmentProduction
368
270
  ```ruby
369
- # Before (Basic)
370
- transport = SmartMessage::Transport.create(:redis, url: 'redis://localhost:6379')
371
-
372
- # After (Enhanced) - maintains backwards compatibility
373
- transport = SmartMessage::Transport::RedisEnhancedTransport.new(
374
- url: 'redis://localhost:6379'
375
- )
376
-
377
- # Add pattern-based subscriptions gradually
378
- transport.where.from('api').subscribe
379
- ```
380
-
381
- ### From Enhanced → Queue
382
- ```ruby
383
- # Before (Enhanced)
384
- class OrderMessage < SmartMessage::Base
385
- transport SmartMessage::Transport::RedisEnhancedTransport.new(url: 'redis://localhost:6379')
386
- end
387
-
388
- # After (Queue) - requires architecture changes
389
- SmartMessage.configure do |config|
390
- config.transport = :redis_queue
391
- config.transport_options = { url: 'redis://localhost:6379' }
271
+ # Development (Memory)
272
+ class MyMessage < SmartMessage::Base
273
+ config do
274
+ transport SmartMessage::Transport.create(:memory, auto_process: true)
275
+ end
392
276
  end
393
277
 
394
- class OrderMessage < SmartMessage::Base
395
- transport :redis_queue
396
-
397
- # Add proper async processing
398
- def self.process(wrapper)
399
- header, payload = wrapper.split
400
- # Handle message processing
278
+ # Production (Redis)
279
+ class MyMessage < SmartMessage::Base
280
+ config do
281
+ transport SmartMessage::Transport.create(:redis,
282
+ url: ENV['REDIS_URL'] || 'redis://localhost:6379'
283
+ )
401
284
  end
402
285
  end
403
286
  ```
404
287
 
405
- ### From Basic → Queue
288
+ ### Environment-Based Configuration
406
289
  ```ruby
407
- # Significant architectural changes required
408
- # Consider Enhanced as intermediate step for easier migration
290
+ class MyMessage < SmartMessage::Base
291
+ config do
292
+ transport case Rails.env
293
+ when 'test'
294
+ SmartMessage::Transport.create(:memory, auto_process: true)
295
+ when 'development'
296
+ SmartMessage::Transport.create(:stdout, loopback: true)
297
+ when 'production'
298
+ SmartMessage::Transport.create(:redis, url: ENV['REDIS_URL'])
299
+ end
300
+ end
301
+ end
409
302
  ```
410
303
 
411
304
  ---
412
305
 
413
- ## 📈 Performance Testing
306
+ ## 📈 Performance Characteristics
414
307
 
415
- ### Benchmark Setup
416
- ```ruby
417
- # Test all three transports
418
- transports = {
419
- basic: SmartMessage::Transport.create(:redis, url: 'redis://localhost:6379'),
420
- enhanced: SmartMessage::Transport::RedisEnhancedTransport.new(url: 'redis://localhost:6379'),
421
- queue: SmartMessage::Transport.create(:redis_queue, url: 'redis://localhost:6379')
422
- }
423
-
424
- # Measure latency, throughput, memory usage
425
- ```
308
+ ### Latency Comparison
309
+ - **Memory**: ~0.1ms (fastest, no serialization)
310
+ - **STDOUT**: ~1ms (JSON formatting overhead)
311
+ - **Redis**: ~1ms (network + serialization)
426
312
 
427
- ### Expected Results
428
- - **Basic**: Lowest latency, highest throughput for simple scenarios
429
- - **Enhanced**: Slight overhead for pattern processing, excellent routing
430
- - **Queue**: Best overall performance with persistence and load balancing
313
+ ### Throughput Comparison
314
+ - **Memory**: Highest (limited by CPU and memory)
315
+ - **STDOUT**: Medium (limited by I/O operations)
316
+ - **Redis**: High (limited by network and Redis performance)
431
317
 
432
- ![Performance Comparison](../assets/images/performance-comparison.svg)
318
+ ### Memory Usage
319
+ - **Memory**: Grows with message volume (configurable limit)
320
+ - **STDOUT**: Minimal (immediate output/write)
321
+ - **Redis**: Low (messages not stored locally)
433
322
 
434
323
  ---
435
324
 
436
325
  ## 🛠️ Configuration Examples
437
326
 
438
- ### Development Environment
327
+ ### Test Environment
439
328
  ```ruby
440
- # Use Enhanced for flexible development routing
441
329
  SmartMessage.configure do |config|
442
- config.default_transport = SmartMessage::Transport::RedisEnhancedTransport.new(
443
- url: 'redis://localhost:6379',
444
- db: 1 # Separate dev database
330
+ config.default_transport = SmartMessage::Transport.create(:memory,
331
+ auto_process: true,
332
+ max_messages: 100
445
333
  )
446
334
  end
447
335
  ```
448
336
 
449
- ### Production Environment
337
+ ### Development Environment
450
338
  ```ruby
451
- # Use Queue for production reliability
452
339
  SmartMessage.configure do |config|
453
- config.transport = :redis_queue
454
- config.transport_options = {
455
- url: ENV['REDIS_URL'],
456
- db: 0,
457
- queue_prefix: 'prod.smart_message',
458
- consumer_group: ENV['CONSUMER_GROUP'] || 'default_workers',
459
- consumer_timeout: 5,
460
- reconnect_attempts: 10
461
- }
340
+ config.default_transport = SmartMessage::Transport.create(:stdout,
341
+ loopback: true,
342
+ output: "log/messages.log"
343
+ )
462
344
  end
463
345
  ```
464
346
 
465
- ### Hybrid Approach
347
+ ### Production Environment
466
348
  ```ruby
467
- # Different transports for different message types
468
- class LogMessage < SmartMessage::Base
469
- transport SmartMessage::Transport.create(:redis, url: 'redis://localhost:6379') # Fire-and-forget
470
- end
471
-
472
- class OrderMessage < SmartMessage::Base
473
- transport :redis_queue # Persistent and reliable
474
- end
475
-
476
- class HealthCheckMessage < SmartMessage::Base
477
- transport SmartMessage::Transport::RedisEnhancedTransport.new(
478
- url: 'redis://localhost:6379'
479
- ) # Pattern-based routing
349
+ SmartMessage.configure do |config|
350
+ config.default_transport = SmartMessage::Transport.create(:redis,
351
+ url: ENV['REDIS_URL'],
352
+ db: ENV['REDIS_DB']&.to_i || 0,
353
+ reconnect_attempts: 10,
354
+ reconnect_delay: 2
355
+ )
480
356
  end
481
357
  ```
482
358
 
483
359
  ---
484
360
 
485
- ## 📚 Additional Resources
486
-
487
- - [Basic Redis Transport Examples](https://github.com/madbomber/smart_message/tree/main/examples/redis_basic)
488
- - [Enhanced Redis Transport Examples](https://github.com/madbomber/smart_message/tree/main/examples/redis_enhanced)
489
- - [Queue Redis Transport Examples](https://github.com/madbomber/smart_message/tree/main/examples/redis_queue)
490
- - [Redis Queue Production Guide](../guides/redis-queue-production.md)
491
- - [Redis Queue Patterns Guide](../guides/redis-queue-patterns.md)
492
- - [Transport Reference](../reference/transports.md)
493
-
494
- ---
495
-
496
- This comparison should help you choose the right Redis transport for your specific use case. Each transport has its strengths and is optimized for different scenarios within the SmartMessage ecosystem.
361
+ This comparison should help you choose the right transport for your specific use case within the SmartMessage ecosystem. Each transport is optimized for different scenarios and provides the flexibility to grow your application from development to production.