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,319 @@
1
+ # Redis Enhanced Transport Examples
2
+
3
+ This directory contains comprehensive examples demonstrating the advanced features of `SmartMessage::Transport::RedisEnhancedTransport`, which extends the basic Redis transport with RabbitMQ-style pattern matching and intelligent routing capabilities.
4
+
5
+ ## 🚀 What is Redis Enhanced Transport?
6
+
7
+ The Redis Enhanced Transport is a powerful extension of the basic Redis transport that provides:
8
+
9
+ - **Pattern-based subscriptions** with wildcard support (`*` and `#`)
10
+ - **Fluent API** for building complex subscription patterns
11
+ - **Dual channel publishing** for backwards compatibility
12
+ - **Enhanced routing** with 3-part channel names: `message_type.from.to`
13
+ - **Convenience methods** for common subscription patterns
14
+
15
+ ## 📊 Visual Guide to Key Concepts
16
+
17
+ ### Pattern Matching System
18
+
19
+ ![Enhanced Pattern Matching](../../docs/assets/images/enhanced-pattern-matching.svg)
20
+
21
+ The enhanced transport uses sophisticated pattern matching to route messages. Unlike basic Redis pub/sub that requires exact channel matches, enhanced transport supports wildcard patterns similar to RabbitMQ:
22
+
23
+ - **Single Wildcard (`*`)**: Matches exactly one segment
24
+ - **Pattern Examples**: `ordermessage.*.*`, `*.payment_gateway.*`, `alertmessage.*.*`
25
+ - **Smart Routing**: Messages are matched against all active patterns automatically
26
+
27
+ ### Fluent API Architecture
28
+
29
+ ![Enhanced Fluent API](../../docs/assets/images/enhanced-fluent-api.svg)
30
+
31
+ The fluent API provides a chainable, readable syntax for building complex subscription patterns:
32
+
33
+ - **Method Chaining**: `transport.where.from('api').to('service').subscribe`
34
+ - **Builder Pattern**: Each method returns a builder for further chaining
35
+ - **Pattern Generation**: Automatically converts fluent calls to optimized patterns
36
+ - **Type Safety**: Validates patterns at build time
37
+
38
+ ### Dual Publishing Strategy
39
+
40
+ ![Enhanced Dual Publishing](../../docs/assets/images/enhanced-dual-publishing.svg)
41
+
42
+ Enhanced transport maintains backwards compatibility through dual channel publishing:
43
+
44
+ - **Backwards Compatible**: Basic Redis subscribers continue to work
45
+ - **Gradual Migration**: Upgrade publishers without breaking existing systems
46
+ - **Dual Channels**: Messages published to both original and enhanced formats
47
+ - **No Performance Penalty**: Efficient Redis handling of multiple channels
48
+
49
+ ### Microservices Routing
50
+
51
+ ![Enhanced Microservices Routing](../../docs/assets/images/enhanced-microservices-routing.svg)
52
+
53
+ Perfect for complex microservices architectures requiring intelligent routing:
54
+
55
+ - **Service-to-Service**: Direct routing between specific services
56
+ - **Cross-Service Types**: Subscribe to message types across all services
57
+ - **Alert Aggregation**: Centralized monitoring and alerting patterns
58
+ - **Dynamic Routing**: Pattern-based routing adapts to service topology changes
59
+
60
+ ## 📁 Example Files
61
+
62
+ ### 1. `enhanced_01_basic_patterns.rb` - Pattern Subscriptions Fundamentals
63
+
64
+ **Focus**: Basic pattern subscription capabilities
65
+
66
+ **Key Features Demonstrated**:
67
+ - Direct pattern subscriptions with wildcards
68
+ - Convenience subscription methods
69
+ - Enhanced vs. original channel publishing
70
+ - Pattern-based message filtering
71
+
72
+ **Run Example**:
73
+ ```bash
74
+ ruby examples/redis_enhanced/enhanced_01_basic_patterns.rb
75
+ ```
76
+
77
+ **Sample Patterns**:
78
+ - `ordermessage.*.*` - All order messages
79
+ - `*.payment_gateway.*` - All messages from payment gateway
80
+ - `alertmessage.*.*` - All alert messages
81
+
82
+ ### 2. `enhanced_02_fluent_api.rb` - Fluent API for Complex Routing
83
+
84
+ **Focus**: Fluent API for building readable subscription patterns
85
+
86
+ **Key Features Demonstrated**:
87
+ - Chainable `.where().from().to().type()` syntax
88
+ - Complex multi-condition subscriptions
89
+ - Microservices communication patterns
90
+ - Pattern building and visualization
91
+
92
+ **Run Example**:
93
+ ```bash
94
+ ruby examples/redis_enhanced/enhanced_02_fluent_api.rb
95
+ ```
96
+
97
+ **Sample Fluent Patterns**:
98
+ ```ruby
99
+ transport.where.from('web-app').to('user-service').subscribe
100
+ transport.where.type('AnalyticsEventMessage').from('web-app').subscribe
101
+ transport.where.from('monitoring').to('admin-panel').type('AdminAlertMessage').subscribe
102
+ ```
103
+
104
+ ### 3. `enhanced_03_dual_publishing.rb` - Backwards Compatibility Demo
105
+
106
+ **Focus**: Dual channel publishing and transport compatibility
107
+
108
+ **Key Features Demonstrated**:
109
+ - Publishing to both original and enhanced channels
110
+ - Backwards compatibility with basic Redis transport
111
+ - Cross-transport message communication
112
+ - Channel naming conventions
113
+
114
+ **Run Example**:
115
+ ```bash
116
+ ruby examples/redis_enhanced/enhanced_03_dual_publishing.rb
117
+ ```
118
+
119
+ **Publishing Behavior**:
120
+ - Enhanced transport → publishes to BOTH channels
121
+ - Basic transport → publishes to original channel only
122
+ - Both can receive messages from each other
123
+
124
+ ### 4. `enhanced_04_advanced_routing.rb` - Complex Microservices Scenarios
125
+
126
+ **Focus**: Advanced routing patterns for complex architectures
127
+
128
+ **Key Features Demonstrated**:
129
+ - Dynamic routing based on message content
130
+ - Service-specific pattern matching
131
+ - Log aggregation and metrics collection routing
132
+ - Complex microservices communication
133
+
134
+ **Run Example**:
135
+ ```bash
136
+ ruby examples/redis_enhanced/enhanced_04_advanced_routing.rb
137
+ ```
138
+
139
+ **Advanced Scenarios**:
140
+ - API Gateway routing to multiple services
141
+ - Database query routing from different ORM layers
142
+ - Log level-based filtering and aggregation
143
+ - Metrics collection from monitoring agents
144
+
145
+ ## 🔧 Prerequisites
146
+
147
+ 1. **Redis Server**: Make sure Redis is running
148
+ ```bash
149
+ # macOS
150
+ brew services start redis
151
+
152
+ # Linux
153
+ sudo service redis start
154
+ ```
155
+
156
+ 2. **Ruby Dependencies**: Install required gems
157
+ ```bash
158
+ bundle install
159
+ ```
160
+
161
+ 3. **SmartMessage**: Ensure you're in the SmartMessage project root
162
+
163
+ ## 🌟 Key Concepts
164
+
165
+ ### Enhanced Channel Format
166
+
167
+ Enhanced channels use a 3-part naming scheme:
168
+ ```
169
+ message_type.from.to
170
+ ```
171
+
172
+ Examples:
173
+ - `ordermessage.api_gateway.order_service`
174
+ - `paymentmessage.payment_service.bank_gateway`
175
+ - `alertmessage.monitoring.admin_panel`
176
+
177
+ ### Pattern Wildcards
178
+
179
+ - `*` - Matches exactly one segment
180
+ - `#` - Matches zero or more segments (Redis doesn't support this natively, but Enhanced Transport simulates it)
181
+
182
+ ### Convenience Methods
183
+
184
+ ```ruby
185
+ transport.subscribe_to_recipient('payment-service') # *.*.payment-service
186
+ transport.subscribe_from_sender('api-gateway') # *.api-gateway.*
187
+ transport.subscribe_to_type('OrderMessage') # ordermessage.*.*
188
+ transport.subscribe_to_alerts # emergency.*.*, *alert*.*.*, etc.
189
+ transport.subscribe_to_broadcasts # *.*.broadcast
190
+ ```
191
+
192
+ ### Fluent API Pattern Building
193
+
194
+ ```ruby
195
+ # Basic patterns
196
+ transport.where.from('service-a').subscribe # *.service-a.*
197
+ transport.where.to('service-b').subscribe # *.*.service-b
198
+ transport.where.type('MessageType').subscribe # messagetype.*.*
199
+
200
+ # Combined patterns
201
+ transport.where.from('api').to('db').subscribe # *.api.db
202
+ transport.where.type('Order').from('web').subscribe # order.web.*
203
+ ```
204
+
205
+ ## 🔍 Monitoring and Debugging
206
+
207
+ ### View Active Patterns
208
+
209
+ Each example shows how to inspect active pattern subscriptions:
210
+
211
+ ```ruby
212
+ pattern_subscriptions = transport.instance_variable_get(:@pattern_subscriptions)
213
+ pattern_subscriptions.each { |pattern| puts pattern }
214
+ ```
215
+
216
+ ### Redis Channel Monitoring
217
+
218
+ You can monitor Redis channels directly:
219
+
220
+ ```bash
221
+ # Monitor all channels
222
+ redis-cli monitor
223
+
224
+ # List active channels
225
+ redis-cli pubsub channels "*"
226
+
227
+ # Monitor specific pattern
228
+ redis-cli psubscribe "ordermessage.*"
229
+ ```
230
+
231
+ ## 🆚 Enhanced vs Basic vs Queue Transports
232
+
233
+ | Feature | Basic Redis | Enhanced Redis | Redis Queue |
234
+ |---------|-------------|----------------|-------------|
235
+ | Channel Format | Class name only | `type.from.to` | Stream-based |
236
+ | Pattern Support | None | Wildcard patterns | RabbitMQ-style |
237
+ | Backwards Compatible | N/A | ✅ Yes | ❌ No |
238
+ | Fluent API | ❌ No | ✅ Yes | ✅ Yes |
239
+ | Persistent Messages | ❌ No | ❌ No | ✅ Yes |
240
+ | Load Balancing | ❌ No | ❌ No | ✅ Yes |
241
+ | Latency | ~1ms | ~1.2ms | ~0.5ms |
242
+ | Concurrent Consumers | ~200 | ~250 | ~1000+ |
243
+ | Memory Overhead | Low | Medium | Medium-High |
244
+ | Setup Complexity | Low | Medium | High |
245
+
246
+ ## 🎯 Use Cases
247
+
248
+ ### When to Use Enhanced Transport
249
+
250
+ - **Microservices Architecture**: Need sophisticated routing between services
251
+ - **Legacy Compatibility**: Must work with existing basic Redis transport
252
+ - **Pattern-Based Routing**: Want RabbitMQ-style patterns without RabbitMQ
253
+ - **Development/Testing**: Need flexible routing for development environments
254
+ - **Gradual Migration**: Moving from basic to more advanced messaging
255
+
256
+ ### When to Use Basic Transport
257
+
258
+ - **Simple Scenarios**: Basic pub/sub without complex routing
259
+ - **Minimal Overhead**: Want lightest-weight solution
260
+ - **Legacy Systems**: Already using basic transport
261
+ - **High Performance**: Need absolute minimum latency
262
+
263
+ ### When to Use Queue Transport
264
+
265
+ - **Production Systems**: Need message persistence and reliability
266
+ - **Load Balancing**: Multiple consumers processing messages
267
+ - **Enterprise Features**: Dead letter queues, consumer groups, etc.
268
+ - **High Throughput**: Maximum concurrent consumers and message rates
269
+
270
+ ## 🚀 Getting Started
271
+
272
+ 1. Start with `enhanced_01_basic_patterns.rb` to understand fundamentals
273
+ 2. Progress through `enhanced_02_fluent_api.rb` for advanced patterns
274
+ 3. Explore `enhanced_03_dual_publishing.rb` for compatibility
275
+ 4. Study `enhanced_04_advanced_routing.rb` for complex scenarios
276
+
277
+ Each example is self-contained and includes detailed explanations of the concepts being demonstrated.
278
+
279
+ ## 📝 Example Output
280
+
281
+ When you run the examples, you'll see detailed output showing:
282
+ - ✅ Subscription confirmations
283
+ - 📤 Message publishing notifications
284
+ - 📦 Message processing with routing details
285
+ - 🔍 Active pattern listings
286
+ - 💡 Key insights and takeaways
287
+
288
+ The examples use emojis and clear formatting to make the output easy to follow and understand.
289
+
290
+ ## 🔗 Related Documentation
291
+
292
+ - **[Transport Comparison Guide](../../docs/transports/redis-transport-comparison.md)** - Detailed comparison of all three Redis transports
293
+ - **[Transport Reference](../../docs/reference/transports.md)** - Complete API reference for enhanced transport
294
+ - **[Architecture Overview](../../docs/core-concepts/architecture.md)** - SmartMessage framework architecture
295
+
296
+ ## 💡 Tips and Best Practices
297
+
298
+ ### Performance Optimization
299
+
300
+ 1. **Use Specific Patterns**: More specific patterns reduce CPU overhead
301
+ 2. **Limit Wildcard Usage**: Excessive wildcards can impact performance
302
+ 3. **Monitor Redis Memory**: Pattern subscriptions consume memory
303
+ 4. **Test Pattern Efficiency**: Use Redis monitoring to validate performance
304
+
305
+ ### Pattern Design Guidelines
306
+
307
+ 1. **Consistent Naming**: Use consistent service and message type names
308
+ 2. **Hierarchical Structure**: Design patterns with clear hierarchies
309
+ 3. **Avoid Over-Engineering**: Start simple, add complexity as needed
310
+ 4. **Document Patterns**: Maintain clear documentation of routing patterns
311
+
312
+ ### Migration Strategy
313
+
314
+ 1. **Start with Dual Publishing**: Enable enhanced transport on publishers first
315
+ 2. **Gradual Subscriber Migration**: Move subscribers one service at a time
316
+ 3. **Monitor Both Channels**: Ensure no message loss during migration
317
+ 4. **Performance Testing**: Validate performance before full deployment
318
+
319
+ Happy messaging! 🎉
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env ruby
2
+ # examples/redis_queue/enhanced_01_basic_patterns.rb
3
+ # Redis Enhanced Transport - Basic Pattern Subscriptions Demo
4
+
5
+ require_relative '../../lib/smart_message'
6
+ require 'smart_message/transport/redis_enhanced_transport'
7
+
8
+ puts "🚀 Redis Enhanced Transport - Basic Pattern Subscriptions Demo"
9
+ puts "=" * 60
10
+
11
+ # Create enhanced Redis transport instance
12
+ transport = SmartMessage::Transport::RedisEnhancedTransport.new(
13
+ url: 'redis://localhost:6379',
14
+ db: 2, # Use database 2 for enhanced transport examples
15
+ auto_subscribe: true
16
+ )
17
+
18
+ #==============================================================================
19
+ # Define Message Classes
20
+ #==============================================================================
21
+
22
+ class OrderMessage < SmartMessage::Base
23
+ from 'e-commerce-api'
24
+ to 'order-processor'
25
+
26
+ transport transport
27
+ serializer SmartMessage::Serializer::Json.new
28
+
29
+ property :order_id, required: true
30
+ property :customer_id, required: true
31
+ property :amount, required: true
32
+ property :items, default: []
33
+
34
+ def self.process(wrapper)
35
+ header, payload = wrapper.split
36
+ data = JSON.parse(payload)
37
+
38
+ puts "📦 [OrderMessage] Processing order #{data['order_id']}"
39
+ puts " Customer: #{data['customer_id']}, Amount: $#{data['amount']}"
40
+ puts " From: #{header.from} → To: #{header.to}"
41
+ puts " Enhanced Channel: ordermessage.#{header.from.gsub('-', '_')}.#{header.to.gsub('-', '_')}"
42
+ puts
43
+ end
44
+ end
45
+
46
+ class PaymentMessage < SmartMessage::Base
47
+ from 'payment-gateway'
48
+ to 'bank-service'
49
+
50
+ transport transport
51
+ serializer SmartMessage::Serializer::Json.new
52
+
53
+ property :payment_id, required: true
54
+ property :amount, required: true
55
+ property :currency, default: 'USD'
56
+
57
+ def self.process(wrapper)
58
+ header, payload = wrapper.split
59
+ data = JSON.parse(payload)
60
+
61
+ puts "💳 [PaymentMessage] Processing payment #{data['payment_id']}"
62
+ puts " Amount: #{data['amount']} #{data['currency']}"
63
+ puts " From: #{header.from} → To: #{header.to}"
64
+ puts " Enhanced Channel: paymentmessage.#{header.from.gsub('-', '_')}.#{header.to.gsub('-', '_')}"
65
+ puts
66
+ end
67
+ end
68
+
69
+ class AlertMessage < SmartMessage::Base
70
+ from 'monitoring-service'
71
+
72
+ transport transport
73
+ serializer SmartMessage::Serializer::Json.new
74
+
75
+ property :alert_type, required: true
76
+ property :severity, required: true
77
+ property :message, required: true
78
+
79
+ def self.process(wrapper)
80
+ header, payload = wrapper.split
81
+ data = JSON.parse(payload)
82
+
83
+ puts "🚨 [AlertMessage] #{data['severity'].upcase} ALERT: #{data['alert_type']}"
84
+ puts " Message: #{data['message']}"
85
+ puts " From: #{header.from} → To: #{header.to || 'broadcast'}"
86
+ puts " Enhanced Channel: alertmessage.#{header.from.gsub('-', '_')}.#{(header.to || 'broadcast').gsub('-', '_')}"
87
+ puts
88
+ end
89
+ end
90
+
91
+ #==============================================================================
92
+ # Demonstration Functions
93
+ #==============================================================================
94
+
95
+ def demo_basic_pattern_subscriptions(transport)
96
+ puts "🔍 Setting up basic pattern subscriptions..."
97
+ puts
98
+
99
+ # Subscribe to specific message patterns
100
+ transport.subscribe_pattern("ordermessage.*.*") # All order messages
101
+ transport.subscribe_pattern("*.payment_gateway.*") # All messages from payment gateway
102
+ transport.subscribe_pattern("*.*.bank_service") # All messages to bank service
103
+ transport.subscribe_pattern("alertmessage.*.*") # All alert messages
104
+
105
+ puts "✅ Subscribed to patterns:"
106
+ puts " • ordermessage.*.* (all order messages)"
107
+ puts " • *.payment_gateway.* (all from payment gateway)"
108
+ puts " • *.*.bank_service (all to bank service)"
109
+ puts " • alertmessage.*.* (all alert messages)"
110
+ puts
111
+ end
112
+
113
+ def demo_convenience_subscriptions(transport)
114
+ puts "🎯 Setting up convenience method subscriptions..."
115
+ puts
116
+
117
+ # Use convenience methods
118
+ transport.subscribe_to_recipient('order-processor')
119
+ transport.subscribe_from_sender('monitoring-service')
120
+ transport.subscribe_to_type('PaymentMessage')
121
+ transport.subscribe_to_alerts # Subscribes to emergency/alert/alarm/critical patterns
122
+ transport.subscribe_to_broadcasts
123
+
124
+ puts "✅ Convenience subscriptions added:"
125
+ puts " • subscribe_to_recipient('order-processor')"
126
+ puts " • subscribe_from_sender('monitoring-service')"
127
+ puts " • subscribe_to_type('PaymentMessage')"
128
+ puts " • subscribe_to_alerts (emergency/alert/alarm/critical patterns)"
129
+ puts " • subscribe_to_broadcasts"
130
+ puts
131
+ end
132
+
133
+ def publish_sample_messages
134
+ puts "📤 Publishing sample messages..."
135
+ puts
136
+
137
+ # Publish order message
138
+ order = OrderMessage.new(
139
+ order_id: 'ORD-001',
140
+ customer_id: 'CUST-123',
141
+ amount: 99.99,
142
+ items: ['Widget A', 'Widget B']
143
+ )
144
+ order.publish
145
+
146
+ # Publish payment message
147
+ payment = PaymentMessage.new(
148
+ payment_id: 'PAY-001',
149
+ amount: 99.99,
150
+ currency: 'USD'
151
+ )
152
+ payment.publish
153
+
154
+ # Publish alert message (broadcast)
155
+ alert = AlertMessage.new(
156
+ alert_type: 'system_overload',
157
+ severity: 'warning',
158
+ message: 'CPU usage exceeding 80%'
159
+ )
160
+ alert.to(nil) # Make it a broadcast
161
+ alert.publish
162
+
163
+ # Publish targeted alert
164
+ critical_alert = AlertMessage.new(
165
+ alert_type: 'database_connection_lost',
166
+ severity: 'critical',
167
+ message: 'Primary database connection failed'
168
+ )
169
+ critical_alert.to('ops-team')
170
+ critical_alert.publish
171
+
172
+ puts "✅ Published 4 sample messages"
173
+ puts
174
+ end
175
+
176
+ #==============================================================================
177
+ # Main Demonstration
178
+ #==============================================================================
179
+
180
+ begin
181
+ puts "🔧 Checking Redis connection..."
182
+ unless transport.connected?
183
+ puts "❌ Redis not available. Please start Redis server:"
184
+ puts " brew services start redis # macOS"
185
+ puts " sudo service redis start # Linux"
186
+ exit 1
187
+ end
188
+ puts "✅ Connected to Redis"
189
+ puts
190
+
191
+ # Set up subscriptions
192
+ demo_basic_pattern_subscriptions(transport)
193
+ demo_convenience_subscriptions(transport)
194
+
195
+ # Subscribe message classes to their handlers
196
+ OrderMessage.subscribe
197
+ PaymentMessage.subscribe
198
+ AlertMessage.subscribe
199
+
200
+ puts "⏳ Waiting for subscriptions to be established..."
201
+ sleep 1
202
+
203
+ # Publish sample messages
204
+ publish_sample_messages
205
+
206
+ puts "⏳ Processing messages (waiting 3 seconds)..."
207
+ sleep 3
208
+
209
+ puts "📊 Pattern Subscription Status:"
210
+ pattern_subscriptions = transport.instance_variable_get(:@pattern_subscriptions)
211
+ if pattern_subscriptions
212
+ pattern_subscriptions.each do |pattern|
213
+ puts " • #{pattern}"
214
+ end
215
+ else
216
+ puts " No pattern subscriptions found"
217
+ end
218
+ puts
219
+
220
+ puts "🎉 Demo completed! Check the output above to see how messages were routed."
221
+ puts "💡 Notice how messages are published to both original channels (OrderMessage)"
222
+ puts " and enhanced channels (ordermessage.e_commerce_api.order_processor)"
223
+
224
+ rescue Interrupt
225
+ puts "\n👋 Demo interrupted by user"
226
+ rescue => e
227
+ puts "💥 Error: #{e.message}"
228
+ puts e.backtrace[0..3]
229
+ ensure
230
+ puts "\n🧹 Cleaning up..."
231
+ transport&.disconnect
232
+ puts "✅ Disconnected from Redis"
233
+ end