smart_message 0.0.10 → 0.0.12

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/deploy-github-pages.yml +38 -0
  3. data/.gitignore +5 -0
  4. data/CHANGELOG.md +30 -0
  5. data/Gemfile.lock +35 -4
  6. data/README.md +169 -71
  7. data/Rakefile +29 -4
  8. data/docs/assets/images/ddq_architecture.svg +130 -0
  9. data/docs/assets/images/dlq_architecture.svg +115 -0
  10. data/docs/assets/images/enhanced-dual-publishing.svg +136 -0
  11. data/docs/assets/images/enhanced-fluent-api.svg +149 -0
  12. data/docs/assets/images/enhanced-microservices-routing.svg +115 -0
  13. data/docs/assets/images/enhanced-pattern-matching.svg +107 -0
  14. data/docs/assets/images/fluent-api-demo.svg +59 -0
  15. data/docs/assets/images/performance-comparison.svg +161 -0
  16. data/docs/assets/images/redis-basic-architecture.svg +53 -0
  17. data/docs/assets/images/redis-enhanced-architecture.svg +88 -0
  18. data/docs/assets/images/redis-queue-architecture.svg +101 -0
  19. data/docs/assets/images/smart_message.jpg +0 -0
  20. data/docs/assets/images/smart_message_walking.jpg +0 -0
  21. data/docs/assets/images/smartmessage_architecture_overview.svg +173 -0
  22. data/docs/assets/images/transport-comparison-matrix.svg +171 -0
  23. data/docs/assets/javascripts/mathjax.js +17 -0
  24. data/docs/assets/stylesheets/extra.css +51 -0
  25. data/docs/{addressing.md → core-concepts/addressing.md} +5 -7
  26. data/docs/{architecture.md → core-concepts/architecture.md} +78 -138
  27. data/docs/{dispatcher.md → core-concepts/dispatcher.md} +21 -21
  28. data/docs/{message_filtering.md → core-concepts/message-filtering.md} +2 -3
  29. data/docs/{message_processing.md → core-concepts/message-processing.md} +17 -17
  30. data/docs/{troubleshooting.md → development/troubleshooting.md} +7 -7
  31. data/docs/{examples.md → getting-started/examples.md} +115 -89
  32. data/docs/{getting-started.md → getting-started/quick-start.md} +47 -18
  33. data/docs/guides/redis-queue-getting-started.md +697 -0
  34. data/docs/guides/redis-queue-patterns.md +889 -0
  35. data/docs/guides/redis-queue-production.md +1091 -0
  36. data/docs/index.md +64 -0
  37. data/docs/{dead_letter_queue.md → reference/dead-letter-queue.md} +2 -3
  38. data/docs/{logging.md → reference/logging.md} +1 -1
  39. data/docs/{message_deduplication.md → reference/message-deduplication.md} +1 -0
  40. data/docs/{proc_handlers_summary.md → reference/proc-handlers.md} +7 -6
  41. data/docs/{serializers.md → reference/serializers.md} +3 -5
  42. data/docs/{transports.md → reference/transports.md} +133 -11
  43. data/docs/transports/memory-transport.md +374 -0
  44. data/docs/transports/redis-enhanced-transport.md +524 -0
  45. data/docs/transports/redis-queue-transport.md +1304 -0
  46. data/docs/transports/redis-transport-comparison.md +496 -0
  47. data/docs/transports/redis-transport.md +509 -0
  48. data/examples/README.md +98 -5
  49. data/examples/city_scenario/911_emergency_call_flow.svg +99 -0
  50. data/examples/city_scenario/README.md +515 -0
  51. data/examples/city_scenario/ai_visitor_intelligence_flow.svg +108 -0
  52. data/examples/city_scenario/citizen.rb +195 -0
  53. data/examples/city_scenario/city_diagram.svg +125 -0
  54. data/examples/city_scenario/common/health_monitor.rb +80 -0
  55. data/examples/city_scenario/common/logger.rb +30 -0
  56. data/examples/city_scenario/emergency_dispatch_center.rb +270 -0
  57. data/examples/city_scenario/fire_department.rb +446 -0
  58. data/examples/city_scenario/fire_emergency_flow.svg +95 -0
  59. data/examples/city_scenario/health_department.rb +100 -0
  60. data/examples/city_scenario/health_monitoring_system.svg +130 -0
  61. data/examples/city_scenario/house.rb +244 -0
  62. data/examples/city_scenario/local_bank.rb +217 -0
  63. data/examples/city_scenario/messages/emergency_911_message.rb +81 -0
  64. data/examples/city_scenario/messages/emergency_resolved_message.rb +43 -0
  65. data/examples/city_scenario/messages/fire_dispatch_message.rb +43 -0
  66. data/examples/city_scenario/messages/fire_emergency_message.rb +45 -0
  67. data/examples/city_scenario/messages/health_check_message.rb +22 -0
  68. data/examples/city_scenario/messages/health_status_message.rb +35 -0
  69. data/examples/city_scenario/messages/police_dispatch_message.rb +46 -0
  70. data/examples/city_scenario/messages/silent_alarm_message.rb +38 -0
  71. data/examples/city_scenario/police_department.rb +316 -0
  72. data/examples/city_scenario/redis_monitor.rb +129 -0
  73. data/examples/city_scenario/redis_stats.rb +743 -0
  74. data/examples/city_scenario/room_for_improvement.md +240 -0
  75. data/examples/city_scenario/security_emergency_flow.svg +95 -0
  76. data/examples/city_scenario/service_internal_architecture.svg +154 -0
  77. data/examples/city_scenario/smart_message_ai_agent.rb +364 -0
  78. data/examples/city_scenario/start_demo.sh +236 -0
  79. data/examples/city_scenario/stop_demo.sh +106 -0
  80. data/examples/city_scenario/visitor.rb +631 -0
  81. data/examples/{10_message_deduplication.rb → memory/01_message_deduplication_demo.rb} +1 -1
  82. data/examples/{09_dead_letter_queue_demo.rb → memory/02_dead_letter_queue_demo.rb} +13 -40
  83. data/examples/{01_point_to_point_orders.rb → memory/03_point_to_point_orders.rb} +1 -1
  84. data/examples/{02_publish_subscribe_events.rb → memory/04_publish_subscribe_events.rb} +2 -2
  85. data/examples/{03_many_to_many_chat.rb → memory/05_many_to_many_chat.rb} +4 -4
  86. data/examples/{show_me.rb → memory/06_pretty_print_demo.rb} +1 -1
  87. data/examples/{05_proc_handlers.rb → memory/07_proc_handlers_demo.rb} +2 -2
  88. data/examples/{06_custom_logger_example.rb → memory/08_custom_logger_demo.rb} +17 -14
  89. data/examples/{07_error_handling_scenarios.rb → memory/09_error_handling_demo.rb} +4 -4
  90. data/examples/{08_entity_addressing_basic.rb → memory/10_entity_addressing_basic.rb} +8 -8
  91. data/examples/{08_entity_addressing_with_filtering.rb → memory/11_entity_addressing_with_filtering.rb} +6 -6
  92. data/examples/{09_regex_filtering_microservices.rb → memory/12_regex_filtering_microservices.rb} +2 -2
  93. data/examples/{10_header_block_configuration.rb → memory/13_header_block_configuration.rb} +6 -6
  94. data/examples/{11_global_configuration_example.rb → memory/14_global_configuration_demo.rb} +19 -8
  95. data/examples/{show_logger.rb → memory/15_logger_demo.rb} +1 -1
  96. data/examples/memory/README.md +163 -0
  97. data/examples/memory/memory_transport_architecture.svg +90 -0
  98. data/examples/memory/point_to_point_pattern.svg +94 -0
  99. data/examples/memory/publish_subscribe_pattern.svg +125 -0
  100. data/examples/{04_redis_smart_home_iot.rb → redis/01_smart_home_iot_demo.rb} +5 -5
  101. data/examples/redis/README.md +230 -0
  102. data/examples/redis/alert_system_flow.svg +127 -0
  103. data/examples/redis/dashboard_status_flow.svg +107 -0
  104. data/examples/redis/device_command_flow.svg +113 -0
  105. data/examples/redis/redis_transport_architecture.svg +115 -0
  106. data/examples/{smart_home_iot_dataflow.md → redis/smart_home_iot_dataflow.md} +4 -116
  107. data/examples/redis/smart_home_system_architecture.svg +133 -0
  108. data/examples/redis_enhanced/README.md +319 -0
  109. data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +233 -0
  110. data/examples/redis_enhanced/enhanced_02_fluent_api.rb +331 -0
  111. data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +281 -0
  112. data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +419 -0
  113. data/examples/redis_queue/01_basic_messaging.rb +221 -0
  114. data/examples/redis_queue/01_comprehensive_examples.rb +508 -0
  115. data/examples/redis_queue/02_pattern_routing.rb +405 -0
  116. data/examples/redis_queue/03_fluent_api.rb +422 -0
  117. data/examples/redis_queue/04_load_balancing.rb +486 -0
  118. data/examples/redis_queue/05_microservices.rb +735 -0
  119. data/examples/redis_queue/06_emergency_alerts.rb +777 -0
  120. data/examples/redis_queue/07_queue_management.rb +587 -0
  121. data/examples/redis_queue/README.md +366 -0
  122. data/examples/redis_queue/enhanced_01_basic_patterns.rb +233 -0
  123. data/examples/redis_queue/enhanced_02_fluent_api.rb +331 -0
  124. data/examples/redis_queue/enhanced_03_dual_publishing.rb +281 -0
  125. data/examples/redis_queue/enhanced_04_advanced_routing.rb +419 -0
  126. data/examples/redis_queue/redis_queue_architecture.svg +148 -0
  127. data/ideas/README.md +41 -0
  128. data/ideas/agents.md +1001 -0
  129. data/ideas/database_transport.md +980 -0
  130. data/ideas/improvement.md +359 -0
  131. data/ideas/meshage.md +1788 -0
  132. data/ideas/message_discovery.md +178 -0
  133. data/ideas/message_schema.md +1381 -0
  134. data/lib/smart_message/.idea/.gitignore +8 -0
  135. data/lib/smart_message/.idea/markdown.xml +6 -0
  136. data/lib/smart_message/.idea/misc.xml +4 -0
  137. data/lib/smart_message/.idea/modules.xml +8 -0
  138. data/lib/smart_message/.idea/smart_message.iml +16 -0
  139. data/lib/smart_message/.idea/vcs.xml +6 -0
  140. data/lib/smart_message/addressing.rb +15 -0
  141. data/lib/smart_message/base.rb +0 -2
  142. data/lib/smart_message/configuration.rb +1 -1
  143. data/lib/smart_message/logger.rb +15 -4
  144. data/lib/smart_message/plugins.rb +5 -2
  145. data/lib/smart_message/serializer.rb +14 -0
  146. data/lib/smart_message/transport/redis_enhanced_transport.rb +399 -0
  147. data/lib/smart_message/transport/redis_queue_transport.rb +555 -0
  148. data/lib/smart_message/transport/registry.rb +1 -0
  149. data/lib/smart_message/transport.rb +34 -1
  150. data/lib/smart_message/version.rb +1 -1
  151. data/lib/smart_message.rb +5 -52
  152. data/mkdocs.yml +184 -0
  153. data/p2p_plan.md +326 -0
  154. data/p2p_roadmap.md +287 -0
  155. data/smart_message.gemspec +2 -0
  156. data/smart_message.svg +51 -0
  157. metadata +170 -44
  158. data/docs/README.md +0 -57
  159. data/examples/dead_letters.jsonl +0 -12
  160. data/examples/temp.txt +0 -94
  161. data/examples/tmux_chat/README.md +0 -283
  162. data/examples/tmux_chat/bot_agent.rb +0 -278
  163. data/examples/tmux_chat/human_agent.rb +0 -199
  164. data/examples/tmux_chat/room_monitor.rb +0 -160
  165. data/examples/tmux_chat/shared_chat_system.rb +0 -328
  166. data/examples/tmux_chat/start_chat_demo.sh +0 -190
  167. data/examples/tmux_chat/stop_chat_demo.sh +0 -22
  168. /data/docs/{properties.md → core-concepts/properties.md} +0 -0
  169. /data/docs/{ideas_to_think_about.md → development/ideas.md} +0 -0
@@ -0,0 +1,524 @@
1
+ # Redis Enhanced Transport
2
+
3
+ The **Redis Enhanced Transport** extends the basic Redis transport with RabbitMQ-style pattern matching and intelligent routing capabilities. It provides sophisticated message routing while maintaining full backwards compatibility with the basic Redis transport.
4
+
5
+ ## Overview
6
+
7
+ Redis Enhanced Transport is perfect for:
8
+ - **Microservices architecture** - Sophisticated routing between services
9
+ - **Pattern-based routing** - RabbitMQ-style patterns without RabbitMQ
10
+ - **Legacy compatibility** - Gradual migration from basic Redis transport
11
+ - **Development flexibility** - Advanced routing for complex applications
12
+
13
+ ## Key Features
14
+
15
+ - 🎯 **Pattern-Based Subscriptions** - Wildcard support (`*` patterns)
16
+ - 🔄 **Dual Channel Publishing** - Backwards compatibility with basic transport
17
+ - 🛠️ **Fluent API** - Chainable subscription building
18
+ - 📡 **Enhanced Routing** - 3-part channel names: `message_type.from.to`
19
+ - 🚀 **High Performance** - ~1.2ms latency, 75K+ messages/second
20
+ - 🔌 **Drop-in Replacement** - Seamless upgrade from basic Redis transport
21
+
22
+ ## Architecture
23
+
24
+ ![Enhanced Transport Architecture](../assets/images/redis-enhanced-architecture.svg)
25
+
26
+ The Enhanced Transport uses a sophisticated 3-part channel naming scheme and publishes to both original and enhanced channels for backward compatibility.
27
+
28
+ ## Channel Format
29
+
30
+ Enhanced channels use a structured naming scheme:
31
+ ```
32
+ message_type.from.to
33
+ ```
34
+
35
+ **Examples**:
36
+ - `ordermessage.api_gateway.order_service`
37
+ - `paymentmessage.payment_service.bank_gateway`
38
+ - `alertmessage.monitoring.admin_panel`
39
+
40
+ ## Pattern Matching
41
+
42
+ ![Pattern Matching System](../assets/images/enhanced-pattern-matching.svg)
43
+
44
+ ### Wildcard Support
45
+ - **`*`** - Matches exactly one segment
46
+ - **Pattern Examples**:
47
+ - `ordermessage.*.*` - All order messages
48
+ - `*.payment_gateway.*` - All messages from payment gateway
49
+ - `alertmessage.*.*` - All alert messages
50
+
51
+ ## Fluent API
52
+
53
+ ![Fluent API Architecture](../assets/images/enhanced-fluent-api.svg)
54
+
55
+ Build complex subscription patterns with chainable methods:
56
+
57
+ ```ruby
58
+ # Basic patterns
59
+ transport.where.from('api-gateway').subscribe # *.api-gateway.*
60
+ transport.where.to('order-service').subscribe # *.*.order-service
61
+ transport.where.type('OrderMessage').subscribe # ordermessage.*.*
62
+
63
+ # Combined patterns
64
+ transport.where.from('api').to('service').subscribe # *.api.service
65
+ transport.where.type('Alert').from('monitoring').subscribe # alert.monitoring.*
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ ### Basic Setup
71
+
72
+ ```ruby
73
+ # Minimal configuration
74
+ transport = SmartMessage::Transport::RedisEnhancedTransport.new
75
+
76
+ # With options
77
+ transport = SmartMessage::Transport::RedisEnhancedTransport.new(
78
+ url: 'redis://localhost:6379',
79
+ db: 0,
80
+ auto_subscribe: true,
81
+ reconnect_attempts: 5,
82
+ reconnect_delay: 1
83
+ )
84
+ ```
85
+
86
+ ### Using with SmartMessage
87
+
88
+ ```ruby
89
+ # Configure as default transport
90
+ SmartMessage.configure do |config|
91
+ config.default_transport = SmartMessage::Transport::RedisEnhancedTransport.new
92
+ end
93
+
94
+ # Enhanced message with routing
95
+ class OrderMessage < SmartMessage::Base
96
+ property :order_id, required: true
97
+ property :customer_id, required: true
98
+
99
+ # Set source and destination for routing
100
+ from 'api-gateway'
101
+ to 'order-service'
102
+
103
+ transport :redis_enhanced
104
+
105
+ def process
106
+ puts "Processing order #{order_id} from #{_sm_header.from} to #{_sm_header.to}"
107
+ end
108
+ end
109
+ ```
110
+
111
+ ## Configuration Options
112
+
113
+ Inherits all options from Redis Transport:
114
+
115
+ | Option | Type | Default | Description |
116
+ |--------|------|---------|-------------|
117
+ | `url` | String | `redis://localhost:6379` | Redis connection URL |
118
+ | `db` | Integer | `0` | Redis database number |
119
+ | `auto_subscribe` | Boolean | `true` | Automatically start subscriber |
120
+ | `reconnect_attempts` | Integer | `5` | Connection retry attempts |
121
+ | `reconnect_delay` | Integer | `1` | Seconds between retries |
122
+
123
+ ## Usage Examples
124
+
125
+ ### Basic Pattern Subscriptions
126
+
127
+ ```ruby
128
+ # Subscribe to all order messages
129
+ OrderMessage.subscribe_pattern('ordermessage.*.*')
130
+
131
+ # Subscribe to messages from specific service
132
+ transport.subscribe_from_sender('payment-gateway')
133
+
134
+ # Subscribe to messages for specific service
135
+ transport.subscribe_to_recipient('order-service')
136
+
137
+ # Subscribe to all messages of a type
138
+ transport.subscribe_to_type('AlertMessage')
139
+ ```
140
+
141
+ ### Fluent API Examples
142
+
143
+ ```ruby
144
+ # Service-specific routing
145
+ transport.where
146
+ .from('web-app')
147
+ .to('user-service')
148
+ .subscribe
149
+
150
+ # Message type filtering
151
+ transport.where
152
+ .type('AnalyticsEvent')
153
+ .from('web-app')
154
+ .subscribe
155
+
156
+ # Complex routing conditions
157
+ transport.where
158
+ .from('monitoring')
159
+ .to('admin-panel')
160
+ .type('AdminAlert')
161
+ .subscribe
162
+ ```
163
+
164
+ ### Microservices Communication
165
+
166
+ ![Microservices Routing](../assets/images/enhanced-microservices-routing.svg)
167
+
168
+ ```ruby
169
+ # API Gateway → Service routing
170
+ class UserRequest < SmartMessage::Base
171
+ property :user_id, required: true
172
+ property :action, required: true
173
+
174
+ from 'api-gateway'
175
+ to 'user-service'
176
+
177
+ def process
178
+ puts "User #{user_id} action: #{action}"
179
+ end
180
+ end
181
+
182
+ # Service → Database routing
183
+ class UserQuery < SmartMessage::Base
184
+ property :query, required: true
185
+
186
+ from 'user-service'
187
+ to 'database'
188
+
189
+ def process
190
+ puts "Executing query: #{query}"
191
+ end
192
+ end
193
+
194
+ # Subscribe to service-specific messages
195
+ transport.where.to('user-service').subscribe # All messages to user service
196
+ transport.where.from('api-gateway').subscribe # All messages from API gateway
197
+ ```
198
+
199
+ ### Convenience Methods
200
+
201
+ ```ruby
202
+ # Subscribe to broadcasts
203
+ transport.subscribe_to_broadcasts # *.*.broadcast
204
+
205
+ # Subscribe to alerts from any service
206
+ transport.subscribe_to_alerts # alertmessage.*.*, *alert*.*.*
207
+
208
+ # Subscribe to specific recipient
209
+ transport.subscribe_to_recipient('payment-service') # *.*.payment-service
210
+
211
+ # Subscribe to specific sender
212
+ transport.subscribe_from_sender('monitoring') # *.monitoring.*
213
+
214
+ # Subscribe to message type
215
+ transport.subscribe_to_type('OrderMessage') # ordermessage.*.*
216
+ ```
217
+
218
+ ## Dual Publishing
219
+
220
+ ![Dual Publishing Strategy](../assets/images/enhanced-dual-publishing.svg)
221
+
222
+ Enhanced Transport maintains backwards compatibility by publishing to both channel formats:
223
+
224
+ ### Publishing Behavior
225
+ ```ruby
226
+ # When OrderMessage publishes:
227
+ OrderMessage.new(order_id: 'ORD-001').publish
228
+
229
+ # Results in publications to BOTH:
230
+ # 1. "OrderMessage" (basic format - for compatibility)
231
+ # 2. "ordermessage.api_gateway.order_service" (enhanced format)
232
+ ```
233
+
234
+ ### Subscriber Compatibility
235
+ - **Basic Redis subscribers** → Receive from original channel
236
+ - **Enhanced Redis subscribers** → Receive from enhanced channel
237
+ - **Both can coexist** → Gradual migration possible
238
+
239
+ ## Advanced Routing Patterns
240
+
241
+ ### Environment-Based Routing
242
+
243
+ ```ruby
244
+ # Development services
245
+ transport.where.to(/^(dev|staging)-.*/).subscribe
246
+
247
+ # Production services
248
+ transport.where.to(/^prod-.*/).subscribe
249
+
250
+ # Cross-environment alerts
251
+ transport.where
252
+ .type('Alert')
253
+ .from(/^(prod|staging)-.*/)
254
+ .to('monitoring')
255
+ .subscribe
256
+ ```
257
+
258
+ ### Service Pattern Routing
259
+
260
+ ```ruby
261
+ # All payment-related services
262
+ transport.where.from(/^payment-.*/).subscribe
263
+
264
+ # API layer to service layer
265
+ transport.where
266
+ .from(/^(web|mobile|api)-.*/)
267
+ .to(/^.*-service$/)
268
+ .subscribe
269
+
270
+ # Monitoring aggregation
271
+ transport.where
272
+ .type('MetricMessage')
273
+ .to('monitoring')
274
+ .subscribe
275
+ ```
276
+
277
+ ### Message Filtering
278
+
279
+ ```ruby
280
+ class AlertMessage < SmartMessage::Base
281
+ property :level, required: true
282
+ property :message, required: true
283
+
284
+ from 'monitoring'
285
+
286
+ def process
287
+ puts "[#{level.upcase}] #{message}"
288
+ end
289
+ end
290
+
291
+ # Subscribe only to critical alerts
292
+ AlertMessage.subscribe(from: 'monitoring') do |message|
293
+ message.level == 'critical'
294
+ end
295
+
296
+ # Subscribe to alerts from specific services
297
+ AlertMessage.subscribe(from: /^(database|api)-.*/)
298
+ ```
299
+
300
+ ## Performance Characteristics
301
+
302
+ - **Latency**: ~1.2ms average (slightly higher due to pattern processing)
303
+ - **Throughput**: 75,000+ messages/second
304
+ - **Memory per Subscriber**: ~2MB (pattern storage overhead)
305
+ - **Concurrent Subscribers**: ~250 practical limit
306
+ - **Pattern Processing**: Minimal CPU overhead
307
+ - **Backwards Compatibility**: No performance penalty
308
+
309
+ ## API Reference
310
+
311
+ ### Pattern Subscription Methods
312
+
313
+ #### `#subscribe_pattern(pattern)`
314
+ Subscribe to messages matching a specific pattern.
315
+
316
+ ```ruby
317
+ transport.subscribe_pattern('ordermessage.*.*')
318
+ transport.subscribe_pattern('*.payment.*')
319
+ ```
320
+
321
+ #### `#where`
322
+ Returns a fluent API builder for complex subscriptions.
323
+
324
+ ```ruby
325
+ builder = transport.where
326
+ builder.from('api').to('service').type('Order').subscribe
327
+ ```
328
+
329
+ #### Convenience Methods
330
+
331
+ ```ruby
332
+ transport.subscribe_to_recipient('service-name') # *.*.service-name
333
+ transport.subscribe_from_sender('service-name') # *.service-name.*
334
+ transport.subscribe_to_type('MessageType') # messagetype.*.*
335
+ transport.subscribe_to_alerts # Alert patterns
336
+ transport.subscribe_to_broadcasts # *.*.broadcast
337
+ ```
338
+
339
+ ### Fluent API Builder Methods
340
+
341
+ #### `#from(service_name)`
342
+ Filter messages from specific service(s).
343
+
344
+ ```ruby
345
+ transport.where.from('api-gateway') # String match
346
+ transport.where.from(/^api-.*/) # Regex match
347
+ transport.where.from(['api', 'web']) # Array match
348
+ ```
349
+
350
+ #### `#to(service_name)`
351
+ Filter messages to specific service(s).
352
+
353
+ ```ruby
354
+ transport.where.to('order-service') # String match
355
+ transport.where.to(/^.*-service$/) # Regex match
356
+ transport.where.to(['user-svc', 'order-svc']) # Array match
357
+ ```
358
+
359
+ #### `#type(message_type)`
360
+ Filter by message type.
361
+
362
+ ```ruby
363
+ transport.where.type('OrderMessage') # String match
364
+ transport.where.type(/^.*Alert$/) # Regex match
365
+ ```
366
+
367
+ #### `#subscribe(&block)`
368
+ Execute the subscription with optional filtering block.
369
+
370
+ ```ruby
371
+ transport.where.from('api').subscribe do |message|
372
+ message.priority == 'high' # Additional filtering
373
+ end
374
+ ```
375
+
376
+ ## Migration from Basic Transport
377
+
378
+ ### Step 1: Enable Enhanced Transport
379
+ ```ruby
380
+ # Before (Basic Redis)
381
+ SmartMessage.configure do |config|
382
+ config.default_transport = SmartMessage::Transport::RedisTransport.new
383
+ end
384
+
385
+ # After (Enhanced Redis)
386
+ SmartMessage.configure do |config|
387
+ config.default_transport = SmartMessage::Transport::RedisEnhancedTransport.new
388
+ end
389
+ ```
390
+
391
+ ### Step 2: Gradual Pattern Adoption
392
+ ```ruby
393
+ # Existing subscriptions continue to work
394
+ OrderMessage.subscribe # Still works exactly the same
395
+
396
+ # New subscriptions can use patterns
397
+ OrderMessage.subscribe_pattern('ordermessage.api.*') # New capability
398
+ ```
399
+
400
+ ### Step 3: Enhanced Message Design
401
+ ```ruby
402
+ # Enhanced messages with routing info
403
+ class NewOrderMessage < SmartMessage::Base
404
+ property :order_id, required: true
405
+
406
+ from 'api-gateway'
407
+ to 'order-service'
408
+
409
+ # Inherits enhanced capabilities automatically
410
+ end
411
+ ```
412
+
413
+ ## Best Practices
414
+
415
+ ### Pattern Design
416
+ - Use consistent service naming conventions
417
+ - Keep patterns as specific as possible for performance
418
+ - Document routing patterns for team understanding
419
+
420
+ ### Service Communication
421
+ - Use meaningful service names in routing
422
+ - Implement service discovery patterns
423
+ - Monitor cross-service message flows
424
+
425
+ ### Backwards Compatibility
426
+ - Test migration thoroughly in staging
427
+ - Monitor both channel formats during transition
428
+ - Maintain basic transport compatibility during migration
429
+
430
+ ### Performance Optimization
431
+ - Limit wildcard usage for high-throughput scenarios
432
+ - Use specific patterns rather than broad wildcards
433
+ - Monitor Redis memory usage with pattern storage
434
+
435
+ ## Use Cases
436
+
437
+ ### Microservices Architecture
438
+ Perfect for complex service topologies requiring intelligent routing.
439
+
440
+ ### Legacy System Migration
441
+ Gradual migration from basic Redis transport without breaking existing functionality.
442
+
443
+ ### Development Environments
444
+ Flexible routing for rapidly changing service architectures.
445
+
446
+ ### Pattern-Based Routing
447
+ Applications requiring RabbitMQ-style routing without RabbitMQ complexity.
448
+
449
+ ## Related Documentation
450
+
451
+ - [Enhanced Transport Examples](https://github.com/madbomber/smart_message/tree/main/examples/redis_enhanced) - Complete working examples
452
+ - [Redis Transport Comparison](redis-transport-comparison.md) - Compare all Redis transports
453
+ - [Redis Queue Transport](redis-queue-transport.md) - Persistent queues with load balancing
454
+ - [Transport Overview](../reference/transports.md) - All available transports
455
+
456
+ ## Examples
457
+
458
+ The `examples/redis_enhanced/` directory contains comprehensive examples demonstrating Redis Enhanced Transport capabilities:
459
+
460
+ ### Advanced Routing Patterns
461
+ - **[enhanced_01_basic_patterns.rb](https://github.com/MadBomber/smart_message/blob/main/examples/redis_enhanced/enhanced_01_basic_patterns.rb)** - Foundation patterns for enhanced routing
462
+ - Simple subscriber patterns with wildcards
463
+ - Basic pattern matching and subscription filtering
464
+ - Enhanced routing setup and configuration
465
+
466
+ - **[enhanced_02_fluent_api.rb](https://github.com/MadBomber/smart_message/blob/main/examples/redis_enhanced/enhanced_02_fluent_api.rb)** - Fluent API usage examples
467
+ - Chain-based subscription configuration
468
+ - Dynamic pattern building and modification
469
+ - Fluent interface for complex routing scenarios
470
+
471
+ - **[enhanced_03_dual_publishing.rb](https://github.com/MadBomber/smart_message/blob/main/examples/redis_enhanced/enhanced_03_dual_publishing.rb)** - Dual publishing strategies
472
+ - Broadcasting to multiple patterns simultaneously
473
+ - Pattern-specific message customization
474
+ - Load balancing across pattern-matched subscribers
475
+
476
+ - **[enhanced_04_advanced_routing.rb](https://github.com/MadBomber/smart_message/blob/main/examples/redis_enhanced/enhanced_04_advanced_routing.rb)** - Complex routing scenarios
477
+ - Multi-level pattern hierarchies
478
+ - Conditional routing based on message content
479
+ - Dynamic subscriber management and pattern updates
480
+
481
+ ### Key Features Demonstrated
482
+
483
+ The enhanced examples showcase unique Redis Enhanced Transport capabilities:
484
+ - **Pattern-Based Subscriptions** - Wildcard and regex pattern matching
485
+ - **Advanced Channel Routing** - Beyond simple class-name channels
486
+ - **Fluent Configuration API** - Chainable subscription setup
487
+ - **Dynamic Routing** - Runtime pattern modification
488
+ - **Complex Message Filtering** - Content-based routing decisions
489
+
490
+ ### Running Examples
491
+
492
+ ```bash
493
+ # Prerequisites: Start Redis server
494
+ redis-server
495
+
496
+ # Navigate to the SmartMessage directory
497
+ cd smart_message
498
+
499
+ # Run enhanced transport examples
500
+ ruby examples/redis_enhanced/enhanced_01_basic_patterns.rb
501
+ ruby examples/redis_enhanced/enhanced_02_fluent_api.rb
502
+ ruby examples/redis_enhanced/enhanced_04_advanced_routing.rb
503
+
504
+ # Monitor pattern-based routing
505
+ redis-cli PSUBSCRIBE "*"
506
+ ```
507
+
508
+ ### Example Patterns
509
+
510
+ The enhanced examples demonstrate these routing patterns:
511
+ - **Service patterns**: `user.*`, `order.*`, `payment.*`
512
+ - **Environment patterns**: `*.dev`, `*.staging`, `*.prod`
513
+ - **Priority patterns**: `urgent.*`, `normal.*`, `low.*`
514
+ - **Geographic patterns**: `*.us-east`, `*.eu-west`, `*.asia`
515
+
516
+ ### Advanced Features
517
+
518
+ The enhanced transport examples also show:
519
+ - **Backward compatibility** with standard Redis Transport
520
+ - **Performance optimizations** for pattern-heavy workloads
521
+ - **Error handling** for pattern mismatch scenarios
522
+ - **Testing strategies** for pattern-based routing
523
+
524
+ Each example builds on the previous ones, showing progressively more sophisticated routing capabilities that make Redis Enhanced Transport ideal for complex, distributed messaging architectures.