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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -1
- data/Gemfile.lock +5 -5
- data/docs/core-concepts/architecture.md +5 -10
- data/docs/getting-started/examples.md +0 -12
- data/docs/getting-started/quick-start.md +4 -9
- data/docs/index.md +4 -4
- data/docs/reference/serializers.md +160 -488
- data/docs/reference/transports.md +1 -125
- data/docs/transports/redis-transport-comparison.md +215 -350
- data/docs/transports/redis-transport.md +3 -22
- data/examples/README.md +6 -9
- data/examples/city_scenario/README.md +1 -1
- data/examples/city_scenario/messages/emergency_911_message.rb +0 -1
- data/examples/city_scenario/messages/emergency_resolved_message.rb +0 -1
- data/examples/city_scenario/messages/fire_dispatch_message.rb +0 -1
- data/examples/city_scenario/messages/fire_emergency_message.rb +0 -1
- data/examples/city_scenario/messages/health_check_message.rb +0 -1
- data/examples/city_scenario/messages/health_status_message.rb +0 -1
- data/examples/city_scenario/messages/police_dispatch_message.rb +0 -1
- data/examples/city_scenario/messages/silent_alarm_message.rb +0 -1
- data/examples/memory/01_message_deduplication_demo.rb +0 -2
- data/examples/memory/02_dead_letter_queue_demo.rb +0 -3
- data/examples/memory/03_point_to_point_orders.rb +0 -2
- data/examples/memory/04_publish_subscribe_events.rb +0 -1
- data/examples/memory/05_many_to_many_chat.rb +0 -3
- data/examples/memory/07_proc_handlers_demo.rb +0 -1
- data/examples/memory/08_custom_logger_demo.rb +0 -4
- data/examples/memory/09_error_handling_demo.rb +0 -3
- data/examples/memory/10_entity_addressing_basic.rb +0 -6
- data/examples/memory/11_entity_addressing_with_filtering.rb +0 -4
- data/examples/memory/12_regex_filtering_microservices.rb +0 -1
- data/examples/memory/13_header_block_configuration.rb +0 -5
- data/examples/memory/14_global_configuration_demo.rb +0 -2
- data/examples/memory/15_logger_demo.rb +0 -1
- data/examples/memory/README.md +3 -3
- data/examples/redis/01_smart_home_iot_demo.rb +0 -4
- data/examples/redis/README.md +0 -2
- data/lib/smart_message/base.rb +19 -10
- data/lib/smart_message/configuration.rb +2 -23
- data/lib/smart_message/dead_letter_queue.rb +1 -1
- data/lib/smart_message/messaging.rb +3 -62
- data/lib/smart_message/plugins.rb +1 -42
- data/lib/smart_message/transport/base.rb +42 -8
- data/lib/smart_message/transport/memory_transport.rb +23 -4
- data/lib/smart_message/transport/redis_transport.rb +11 -0
- data/lib/smart_message/transport/registry.rb +0 -1
- data/lib/smart_message/transport/stdout_transport.rb +28 -10
- data/lib/smart_message/transport.rb +0 -1
- data/lib/smart_message/version.rb +1 -1
- metadata +2 -28
- data/docs/guides/redis-queue-getting-started.md +0 -697
- data/docs/guides/redis-queue-patterns.md +0 -889
- data/docs/guides/redis-queue-production.md +0 -1091
- data/docs/transports/redis-enhanced-transport.md +0 -524
- data/docs/transports/redis-queue-transport.md +0 -1304
- data/examples/redis_enhanced/README.md +0 -319
- data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +0 -233
- data/examples/redis_enhanced/enhanced_02_fluent_api.rb +0 -331
- data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +0 -281
- data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +0 -419
- data/examples/redis_queue/01_basic_messaging.rb +0 -221
- data/examples/redis_queue/01_comprehensive_examples.rb +0 -508
- data/examples/redis_queue/02_pattern_routing.rb +0 -405
- data/examples/redis_queue/03_fluent_api.rb +0 -422
- data/examples/redis_queue/04_load_balancing.rb +0 -486
- data/examples/redis_queue/05_microservices.rb +0 -735
- data/examples/redis_queue/06_emergency_alerts.rb +0 -777
- data/examples/redis_queue/07_queue_management.rb +0 -587
- data/examples/redis_queue/README.md +0 -366
- data/examples/redis_queue/enhanced_01_basic_patterns.rb +0 -233
- data/examples/redis_queue/enhanced_02_fluent_api.rb +0 -331
- data/examples/redis_queue/enhanced_03_dual_publishing.rb +0 -281
- data/examples/redis_queue/enhanced_04_advanced_routing.rb +0 -419
- data/examples/redis_queue/redis_queue_architecture.svg +0 -148
- data/lib/smart_message/transport/redis_enhanced_transport.rb +0 -399
- data/lib/smart_message/transport/redis_queue_transport.rb +0 -555
@@ -1,496 +1,361 @@
|
|
1
|
-
#
|
1
|
+
# Transport Comparison
|
2
2
|
|
3
|
-
SmartMessage provides
|
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
|
-
| **
|
10
|
-
| **
|
11
|
-
| **Redis
|
12
|
-
|
13
|
-

|
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
|
-
##
|
15
|
+
## 🧠 Memory Transport
|
18
16
|
|
19
|
-
|
17
|
+
Perfect for development, testing, and in-memory message queuing.
|
20
18
|
|
21
19
|
### Architecture
|
22
20
|
```
|
23
|
-
Publisher →
|
24
|
-
(
|
21
|
+
Publisher → Memory Queue → Subscriber
|
22
|
+
(thread-safe) (auto-processing)
|
25
23
|
```
|
26
24
|
|
27
|
-

|
28
|
-
|
29
25
|
### Key Characteristics
|
30
|
-
- **
|
31
|
-
- **Pattern Support**: None -
|
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**:
|
35
|
-
- **
|
29
|
+
- **Threading**: Thread-safe with mutex protection
|
30
|
+
- **External Dependencies**: None
|
36
31
|
|
37
32
|
### Configuration
|
38
33
|
```ruby
|
39
|
-
SmartMessage::Transport.create(:
|
40
|
-
|
41
|
-
|
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
|
-
- **
|
50
|
-
- **Development
|
51
|
-
- **
|
52
|
-
- **
|
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
|
-
- ✅
|
57
|
-
- ✅
|
58
|
-
- ✅
|
59
|
-
- ✅
|
60
|
-
- ✅
|
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
|
-
- ❌
|
64
|
-
- ❌
|
65
|
-
- ❌
|
66
|
-
- ❌
|
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
|
72
|
-
|
73
|
-
url: 'redis://localhost:6379'
|
74
|
-
)
|
61
|
+
class TestMessage < SmartMessage::Base
|
62
|
+
property :data
|
75
63
|
|
76
|
-
|
77
|
-
|
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
|
-
|
81
|
-
|
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
|
-
##
|
79
|
+
## 📄 STDOUT Transport
|
90
80
|
|
91
|
-
|
81
|
+
Ideal for development, debugging, and logging scenarios.
|
92
82
|
|
93
83
|
### Architecture
|
94
84
|
```
|
95
|
-
Publisher →
|
96
|
-
(
|
85
|
+
Publisher → Console/File Output → Optional Loopback → Subscriber
|
86
|
+
(JSON formatting) (if enabled) (local processing)
|
97
87
|
```
|
98
88
|
|
99
|
-

|
100
|
-
|
101
89
|
### Key Characteristics
|
102
|
-
- **
|
103
|
-
- **Pattern Support**:
|
104
|
-
- **
|
105
|
-
- **
|
106
|
-
- **
|
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
|
112
|
-
|
113
|
-
|
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
|
-

|
144
|
-
|
145
104
|
### Use Cases
|
146
|
-
- **
|
147
|
-
- **
|
148
|
-
- **
|
149
|
-
- **
|
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
|
-
- ✅
|
154
|
-
- ✅
|
155
|
-
- ✅
|
156
|
-
- ✅
|
157
|
-
- ✅
|
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
|
-
- ❌
|
162
|
-
- ❌
|
163
|
-
- ❌
|
164
|
-
- ❌
|
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
|
170
|
-
|
171
|
-
|
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
|
-
|
178
|
-
|
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
|
-
|
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
|
-
##
|
143
|
+
## 🔴 Redis Transport
|
194
144
|
|
195
|
-
Production-
|
145
|
+
Production-ready Redis pub/sub transport for distributed messaging.
|
196
146
|
|
197
147
|
### Architecture
|
198
148
|
```
|
199
|
-
Publisher →
|
200
|
-
(
|
149
|
+
Publisher → Redis Channel → Subscriber
|
150
|
+
(pub/sub) (thread-based)
|
201
151
|
```
|
202
152
|
|
203
|
-

|
204
|
-
|
205
153
|
### Key Characteristics
|
206
|
-
- **
|
207
|
-
- **Pattern Support**:
|
208
|
-
- **
|
209
|
-
- **
|
210
|
-
- **
|
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.
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
265
|
-
- **
|
266
|
-
- **
|
267
|
-
- **
|
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
|
-
- ✅
|
272
|
-
- ✅
|
273
|
-
- ✅
|
274
|
-
- ✅
|
275
|
-
- ✅
|
276
|
-
- ✅
|
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
|
-
- ❌
|
281
|
-
- ❌ No
|
282
|
-
- ❌
|
283
|
-
- ❌
|
284
|
-
- ❌
|
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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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 |
|
316
|
-
|
317
|
-
| **Message Persistence** | ❌
|
318
|
-
| **
|
319
|
-
| **
|
320
|
-
| **
|
321
|
-
| **
|
322
|
-
| **
|
323
|
-
| **Performance (
|
324
|
-
| **
|
325
|
-
| **
|
326
|
-
| **
|
327
|
-
| **
|
328
|
-
| **Production Ready** |
|
329
|
-
| **
|
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
|
340
|
-
- ✅ You
|
341
|
-
- ✅
|
342
|
-
- ✅ You need
|
343
|
-
- ✅ You
|
344
|
-
- ✅
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
- ✅ You need
|
349
|
-
- ✅ You
|
350
|
-
- ✅ You want
|
351
|
-
- ✅ You need
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
- ✅ You
|
357
|
-
- ✅ You
|
358
|
-
- ✅ You
|
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
|
267
|
+
## 🔄 Migration Patterns
|
366
268
|
|
367
|
-
###
|
269
|
+
### Development → Production
|
368
270
|
```ruby
|
369
|
-
#
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
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
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
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
|
-
###
|
288
|
+
### Environment-Based Configuration
|
406
289
|
```ruby
|
407
|
-
|
408
|
-
|
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
|
306
|
+
## 📈 Performance Characteristics
|
414
307
|
|
415
|
-
###
|
416
|
-
|
417
|
-
|
418
|
-
|
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
|
-
###
|
428
|
-
- **
|
429
|
-
- **
|
430
|
-
- **
|
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
|
-
|
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
|
-
###
|
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
|
443
|
-
|
444
|
-
|
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
|
-
###
|
337
|
+
### Development Environment
|
450
338
|
```ruby
|
451
|
-
# Use Queue for production reliability
|
452
339
|
SmartMessage.configure do |config|
|
453
|
-
config.
|
454
|
-
|
455
|
-
|
456
|
-
|
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
|
-
###
|
347
|
+
### Production Environment
|
466
348
|
```ruby
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
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
|
-
|
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.
|