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,405 @@
1
+ #!/usr/bin/env ruby
2
+ # examples/redis_queue/02_pattern_routing.rb
3
+ # Advanced pattern-based routing with Redis Queue Transport
4
+
5
+ require_relative '../../lib/smart_message'
6
+ require 'async'
7
+
8
+ puts "🎯 Redis Queue Transport - Pattern Routing Demo"
9
+ puts "=" * 50
10
+
11
+ #==============================================================================
12
+ # Transport Configuration
13
+ #==============================================================================
14
+
15
+ # Create transport instance for pattern subscriptions
16
+ transport = SmartMessage::Transport::RedisQueueTransport.new(
17
+ url: 'redis://localhost:6379',
18
+ db: 2, # Use database 2 for pattern examples
19
+ queue_prefix: 'pattern_demo',
20
+ exchange_name: 'smart_message',
21
+ consumer_timeout: 1, # 1 second timeout for demo responsiveness
22
+ test_mode: false # Enable consumer tasks
23
+ )
24
+
25
+ #==============================================================================
26
+ # Message Classes with Enhanced Headers
27
+ #==============================================================================
28
+
29
+ class ServiceMessage < SmartMessage::Base
30
+ transport :redis_queue, {
31
+ url: 'redis://localhost:6379',
32
+ db: 2,
33
+ queue_prefix: 'pattern_demo',
34
+ exchange_name: 'smart_message',
35
+ test_mode: false
36
+ }
37
+
38
+ property :service_name, required: true
39
+ property :action, required: true
40
+ property :payload, default: {}
41
+ property :request_id, default: -> { SecureRandom.uuid }
42
+
43
+ def process
44
+ puts "🔧 Service: #{service_name} | Action: #{action} | ID: #{request_id}"
45
+ end
46
+ end
47
+
48
+ class NotificationMessage < SmartMessage::Base
49
+ transport :redis_queue, {
50
+ url: 'redis://localhost:6379',
51
+ db: 2,
52
+ queue_prefix: 'pattern_demo'
53
+ }
54
+
55
+ property :notification_type, required: true
56
+ property :recipient, required: true
57
+ property :message_text, required: true
58
+ property :priority, default: 'normal'
59
+
60
+ def process
61
+ priority_icon = case priority
62
+ when 'urgent' then '🚨'
63
+ when 'high' then '❗'
64
+ when 'normal' then '📢'
65
+ when 'low' then '📝'
66
+ else '📢'
67
+ end
68
+
69
+ puts "#{priority_icon} Notification [#{notification_type}] → #{recipient}: #{message_text}"
70
+ end
71
+ end
72
+
73
+ class OrderMessage < SmartMessage::Base
74
+ transport :redis_queue, {
75
+ url: 'redis://localhost:6379',
76
+ db: 2,
77
+ queue_prefix: 'pattern_demo',
78
+ exchange_name: 'smart_message',
79
+ test_mode: false
80
+ }
81
+
82
+ property :order_id, required: true
83
+ property :customer_id, required: true
84
+ property :amount, required: true
85
+ property :status, default: 'pending'
86
+
87
+ def process
88
+ puts "🛒 Order #{order_id}: Customer #{customer_id} - $#{amount} [#{status}]"
89
+ end
90
+ end
91
+
92
+ #==============================================================================
93
+ # Pattern Subscription Setup
94
+ #==============================================================================
95
+
96
+ Async do
97
+ puts "\n🔗 Setting up pattern subscriptions:"
98
+
99
+ # 1. Subscribe to messages TO specific services
100
+ puts "1️⃣ Subscribing to messages directed TO 'payment_service'"
101
+ transport.subscribe_pattern("#.*.payment_service") do |message_class, message_data|
102
+ data = JSON.parse(message_data)
103
+ puts "💳 Payment Service received: #{message_class} - #{data['action'] || data['notification_type'] || data['order_id']}"
104
+ end
105
+
106
+ puts "2️⃣ Subscribing to messages directed TO 'notification_service'"
107
+ transport.subscribe_pattern("#.*.notification_service") do |message_class, message_data|
108
+ data = JSON.parse(message_data)
109
+ puts "📧 Notification Service received: #{message_class} - #{data['message_text'] || data['action']}"
110
+ end
111
+
112
+ # 2. Subscribe to messages FROM specific services
113
+ puts "3️⃣ Subscribing to messages FROM 'api_gateway'"
114
+ transport.subscribe_pattern("#.api_gateway.*") do |message_class, message_data|
115
+ data = JSON.parse(message_data)
116
+ puts "🌐 From API Gateway: #{message_class} - #{data['action'] || data['order_id']}"
117
+ end
118
+
119
+ puts "4️⃣ Subscribing to messages FROM 'mobile_app'"
120
+ transport.subscribe_pattern("#.mobile_app.*") do |message_class, message_data|
121
+ data = JSON.parse(message_data)
122
+ puts "📱 From Mobile App: #{message_class} - #{data['action'] || data['order_id']}"
123
+ end
124
+
125
+ # 3. Subscribe to specific message types
126
+ puts "5️⃣ Subscribing to ALL order messages"
127
+ transport.subscribe_pattern("order.#.*.*") do |message_class, message_data|
128
+ data = JSON.parse(message_data)
129
+ puts "📋 Order Audit: #{data['order_id']} - $#{data['amount']} [#{data['status']}]"
130
+ end
131
+
132
+ puts "6️⃣ Subscribing to ALL notification messages"
133
+ transport.subscribe_pattern("notification.#.*.*") do |message_class, message_data|
134
+ data = JSON.parse(message_data)
135
+ puts "📊 Notification Log: #{data['notification_type']} → #{data['recipient']} [#{data['priority']}]"
136
+ end
137
+
138
+ # 4. Subscribe to urgent messages across all services
139
+ puts "7️⃣ Subscribing to urgent notifications from ANY service"
140
+ transport.subscribe_pattern("notification.#.*.#") do |message_class, message_data|
141
+ data = JSON.parse(message_data)
142
+ if data['priority'] == 'urgent'
143
+ puts "🚨 URGENT ALERT: #{data['message_text']} → #{data['recipient']}"
144
+ end
145
+ end
146
+
147
+ # 5. Subscribe to broadcast messages
148
+ puts "8️⃣ Subscribing to broadcast messages"
149
+ transport.subscribe_pattern("#.*.broadcast") do |message_class, message_data|
150
+ data = JSON.parse(message_data)
151
+ puts "📻 Broadcast: #{message_class} - #{data['message_text'] || data['action']}"
152
+ end
153
+
154
+ # Wait for subscriptions to initialize
155
+ sleep 1
156
+
157
+ #============================================================================
158
+ # Pattern Routing Demonstration
159
+ #============================================================================
160
+
161
+ puts "\n📤 Publishing messages with different routing patterns:"
162
+
163
+ # Messages directed to payment service
164
+ puts "\n🔸 Messages TO payment_service:"
165
+ ServiceMessage.new(
166
+ service_name: 'payment_service',
167
+ action: 'process_payment',
168
+ payload: { amount: 99.99, card_token: 'tok_123' },
169
+ _sm_header: {
170
+ from: 'api_gateway',
171
+ to: 'payment_service'
172
+ }
173
+ ).publish
174
+
175
+ OrderMessage.new(
176
+ order_id: 'ORD-001',
177
+ customer_id: 'CUST-123',
178
+ amount: 99.99,
179
+ status: 'payment_pending',
180
+ _sm_header: {
181
+ from: 'order_service',
182
+ to: 'payment_service'
183
+ }
184
+ ).publish
185
+
186
+ # Messages directed to notification service
187
+ puts "\n🔸 Messages TO notification_service:"
188
+ NotificationMessage.new(
189
+ notification_type: 'email',
190
+ recipient: 'user@example.com',
191
+ message_text: 'Your order has been confirmed',
192
+ priority: 'normal',
193
+ _sm_header: {
194
+ from: 'order_service',
195
+ to: 'notification_service'
196
+ }
197
+ ).publish
198
+
199
+ ServiceMessage.new(
200
+ service_name: 'notification_service',
201
+ action: 'send_sms',
202
+ payload: { phone: '+1234567890', message: 'OTP: 123456' },
203
+ _sm_header: {
204
+ from: 'auth_service',
205
+ to: 'notification_service'
206
+ }
207
+ ).publish
208
+
209
+ # Messages FROM api_gateway
210
+ puts "\n🔸 Messages FROM api_gateway:"
211
+ ServiceMessage.new(
212
+ service_name: 'user_service',
213
+ action: 'create_user',
214
+ payload: { name: 'John Doe', email: 'john@example.com' },
215
+ _sm_header: {
216
+ from: 'api_gateway',
217
+ to: 'user_service'
218
+ }
219
+ ).publish
220
+
221
+ OrderMessage.new(
222
+ order_id: 'ORD-002',
223
+ customer_id: 'CUST-456',
224
+ amount: 149.50,
225
+ status: 'pending',
226
+ _sm_header: {
227
+ from: 'api_gateway',
228
+ to: 'order_service'
229
+ }
230
+ ).publish
231
+
232
+ # Messages FROM mobile_app
233
+ puts "\n🔸 Messages FROM mobile_app:"
234
+ NotificationMessage.new(
235
+ notification_type: 'push',
236
+ recipient: 'device_token_123',
237
+ message_text: 'New message from friend',
238
+ priority: 'normal',
239
+ _sm_header: {
240
+ from: 'mobile_app',
241
+ to: 'notification_service'
242
+ }
243
+ ).publish
244
+
245
+ OrderMessage.new(
246
+ order_id: 'ORD-003',
247
+ customer_id: 'CUST-789',
248
+ amount: 24.99,
249
+ status: 'cart_pending',
250
+ _sm_header: {
251
+ from: 'mobile_app',
252
+ to: 'cart_service'
253
+ }
254
+ ).publish
255
+
256
+ # Urgent notifications
257
+ puts "\n🔸 Urgent notifications:"
258
+ NotificationMessage.new(
259
+ notification_type: 'alert',
260
+ recipient: 'admin@company.com',
261
+ message_text: 'Server CPU usage above 95%',
262
+ priority: 'urgent',
263
+ _sm_header: {
264
+ from: 'monitoring_service',
265
+ to: 'admin_service'
266
+ }
267
+ ).publish
268
+
269
+ NotificationMessage.new(
270
+ notification_type: 'security',
271
+ recipient: 'security@company.com',
272
+ message_text: 'Suspicious login attempt detected',
273
+ priority: 'urgent',
274
+ _sm_header: {
275
+ from: 'security_service',
276
+ to: 'admin_service'
277
+ }
278
+ ).publish
279
+
280
+ # Broadcast messages
281
+ puts "\n🔸 Broadcast messages:"
282
+ NotificationMessage.new(
283
+ notification_type: 'system',
284
+ recipient: 'all_users',
285
+ message_text: 'Scheduled maintenance in 1 hour',
286
+ priority: 'high',
287
+ _sm_header: {
288
+ from: 'admin_service',
289
+ to: 'broadcast'
290
+ }
291
+ ).publish
292
+
293
+ ServiceMessage.new(
294
+ service_name: 'all_services',
295
+ action: 'health_check',
296
+ payload: { timestamp: Time.now.to_i },
297
+ _sm_header: {
298
+ from: 'monitoring_service',
299
+ to: 'broadcast'
300
+ }
301
+ ).publish
302
+
303
+ # Wait for all messages to be processed
304
+ puts "\n⏳ Processing messages with pattern routing..."
305
+ sleep 5
306
+
307
+ #============================================================================
308
+ # Advanced Pattern Examples
309
+ #============================================================================
310
+
311
+ puts "\n🎓 Advanced Pattern Examples:"
312
+
313
+ # Complex multi-service workflow
314
+ puts "\n🔸 Multi-service workflow:"
315
+ ServiceMessage.new(
316
+ service_name: 'inventory_service',
317
+ action: 'reserve_items',
318
+ payload: { order_id: 'ORD-004', items: ['ITEM-001', 'ITEM-002'] },
319
+ _sm_header: {
320
+ from: 'order_service',
321
+ to: 'inventory_service'
322
+ }
323
+ ).publish
324
+
325
+ ServiceMessage.new(
326
+ service_name: 'shipping_service',
327
+ action: 'calculate_shipping',
328
+ payload: { order_id: 'ORD-004', zip_code: '12345' },
329
+ _sm_header: {
330
+ from: 'order_service',
331
+ to: 'shipping_service'
332
+ }
333
+ ).publish
334
+
335
+ # Environment-specific routing
336
+ puts "\n🔸 Environment-specific routing:"
337
+ ServiceMessage.new(
338
+ service_name: 'logging_service',
339
+ action: 'log_event',
340
+ payload: { event: 'user_login', user_id: 'user_123' },
341
+ _sm_header: {
342
+ from: 'auth_service',
343
+ to: 'prod_logging_service'
344
+ }
345
+ ).publish
346
+
347
+ ServiceMessage.new(
348
+ service_name: 'analytics_service',
349
+ action: 'track_event',
350
+ payload: { event: 'page_view', page: '/dashboard' },
351
+ _sm_header: {
352
+ from: 'web_app',
353
+ to: 'dev_analytics_service'
354
+ }
355
+ ).publish
356
+
357
+ sleep 3
358
+
359
+ #============================================================================
360
+ # Pattern Statistics and Routing Table
361
+ #============================================================================
362
+
363
+ puts "\n📊 Pattern Routing Statistics:"
364
+
365
+ # Show routing table
366
+ routing_table = transport.routing_table
367
+ puts "\nActive routing patterns:"
368
+ routing_table.each do |pattern, queues|
369
+ puts " Pattern: '#{pattern}'"
370
+ puts " Queues: #{queues.join(', ')}"
371
+ end
372
+
373
+ # Show queue statistics
374
+ stats = transport.queue_stats
375
+ puts "\nQueue statistics:"
376
+ stats.each do |queue_name, info|
377
+ puts " #{queue_name}:"
378
+ puts " Length: #{info[:length]} messages"
379
+ puts " Pattern: #{info[:pattern]}"
380
+ puts " Consumers: #{info[:consumers]}"
381
+ puts ""
382
+ end
383
+
384
+ # Cleanup
385
+ transport.disconnect
386
+ end
387
+
388
+ puts "\n🎯 Pattern routing demonstration completed!"
389
+ puts "\n💡 Patterns Demonstrated:"
390
+ puts " ✓ TO-based routing: #.*.service_name"
391
+ puts " ✓ FROM-based routing: #.sender.*"
392
+ puts " ✓ Type-based routing: message_type.#.*.*"
393
+ puts " ✓ Priority routing: Complex conditional patterns"
394
+ puts " ✓ Broadcast routing: #.*.broadcast"
395
+ puts " ✓ Multi-pattern subscriptions"
396
+ puts " ✓ Wildcard pattern matching (#, *)"
397
+ puts " ✓ Queue statistics and monitoring"
398
+
399
+ puts "\n🚀 Key Benefits:"
400
+ puts " • Surgical message routing precision"
401
+ puts " • Multiple subscribers per pattern"
402
+ puts " • High-performance pattern matching with Async fibers"
403
+ puts " • Real-time queue monitoring"
404
+ puts " • Flexible routing table management"
405
+ puts " • Fiber-based concurrency for massive scalability"