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,99 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="800" height="600" viewBox="0 0 800 600" xmlns="http://www.w3.org/2000/svg">
3
+ <defs>
4
+ <style>
5
+ .bg { fill: transparent; }
6
+ .participant { fill: #2a2a2a; stroke: #4a9eff; stroke-width: 2; rx: 8; }
7
+ .citizen { fill: #1a3a1a; stroke: #4aff4a; stroke-width: 2; rx: 8; }
8
+ .dispatch { fill: #3a1a1a; stroke: #ff4a4a; stroke-width: 2; rx: 8; }
9
+ .fire { fill: #4a2a1a; stroke: #ffaa4a; stroke-width: 2; rx: 8; }
10
+ .police { fill: #1a2a3a; stroke: #4aafff; stroke-width: 2; rx: 8; }
11
+ .message { stroke: #ffaa4a; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
12
+ .response { stroke: #4aff4a; stroke-width: 2; fill: none; marker-end: url(#arrowhead-green); stroke-dasharray: 5,3; }
13
+ .text { fill: #ffffff; font-family: 'Arial', sans-serif; font-size: 12px; }
14
+ .title { fill: #4a9eff; font-family: 'Arial', sans-serif; font-size: 18px; font-weight: bold; }
15
+ .subtitle { fill: #ffaa4a; font-family: 'Arial', sans-serif; font-size: 11px; }
16
+ .note { fill: #aaaaaa; font-family: 'Arial', sans-serif; font-size: 10px; }
17
+ </style>
18
+ <marker id="arrowhead" markerWidth="8" markerHeight="6"
19
+ refX="8" refY="3" orient="auto">
20
+ <polygon points="0 0, 8 3, 0 6" fill="#ffaa4a" />
21
+ </marker>
22
+ <marker id="arrowhead-green" markerWidth="8" markerHeight="6"
23
+ refX="8" refY="3" orient="auto">
24
+ <polygon points="0 0, 8 3, 0 6" fill="#4aff4a" />
25
+ </marker>
26
+ </defs>
27
+
28
+ <!-- Background -->
29
+ <rect class="bg" width="800" height="600"/>
30
+
31
+ <!-- Title -->
32
+ <text x="400" y="25" text-anchor="middle" class="title">911 Emergency Call Flow</text>
33
+ <text x="400" y="45" text-anchor="middle" class="subtitle">Citizen Emergency Reporting and Department Dispatch</text>
34
+
35
+ <!-- Participants -->
36
+ <rect x="50" y="80" width="120" height="60" class="citizen"/>
37
+ <text x="110" y="105" text-anchor="middle" class="text">👤 Citizen</text>
38
+ <text x="110" y="125" text-anchor="middle" class="subtitle">Emergency Reporter</text>
39
+
40
+ <rect x="250" y="80" width="120" height="60" class="dispatch"/>
41
+ <text x="310" y="105" text-anchor="middle" class="text">📞 Emergency</text>
42
+ <text x="310" y="120" text-anchor="middle" class="text">Dispatch (911)</text>
43
+
44
+ <rect x="450" y="80" width="120" height="60" class="fire"/>
45
+ <text x="510" y="105" text-anchor="middle" class="text">🚒 Fire</text>
46
+ <text x="510" y="120" text-anchor="middle" class="text">Department</text>
47
+
48
+ <rect x="620" y="80" width="120" height="60" class="police"/>
49
+ <text x="680" y="105" text-anchor="middle" class="text">👮 Police</text>
50
+ <text x="680" y="120" text-anchor="middle" class="text">Department</text>
51
+
52
+ <!-- Vertical lifelines -->
53
+ <line x1="110" y1="140" x2="110" y2="550" stroke="#666" stroke-width="2" stroke-dasharray="3,3"/>
54
+ <line x1="310" y1="140" x2="310" y2="550" stroke="#666" stroke-width="2" stroke-dasharray="3,3"/>
55
+ <line x1="510" y1="140" x2="510" y2="550" stroke="#666" stroke-width="2" stroke-dasharray="3,3"/>
56
+ <line x1="680" y1="140" x2="680" y2="550" stroke="#666" stroke-width="2" stroke-dasharray="3,3"/>
57
+
58
+ <!-- Message Flow -->
59
+ <!-- 1. Emergency call -->
60
+ <path d="M 110 180 L 310 180" class="message"/>
61
+ <text x="210" y="175" text-anchor="middle" class="text">Emergency911Message</text>
62
+ <rect x="150" y="185" width="120" height="40" fill="#1a1a1a" stroke="#ffaa4a" rx="4"/>
63
+ <text x="210" y="200" text-anchor="middle" class="note">Reports emergency</text>
64
+ <text x="210" y="215" text-anchor="middle" class="note">Type: fire/medical/crime</text>
65
+
66
+ <!-- 2. Internal analysis -->
67
+ <rect x="280" y="240" width="60" height="30" fill="#3a1a1a" stroke="#ff4a4a" rx="4"/>
68
+ <text x="310" y="260" text-anchor="middle" class="note">Analyze call &amp;</text>
69
+ <text x="310" y="275" text-anchor="middle" class="note">determine dispatch</text>
70
+
71
+ <!-- 3a. Fire/Medical dispatch -->
72
+ <path d="M 310 320 L 510 320" class="message"/>
73
+ <text x="410" y="315" text-anchor="middle" class="text">FireEmergencyMessage</text>
74
+ <text x="410" y="335" text-anchor="middle" class="note">(if fire)</text>
75
+
76
+ <!-- 3b. Fire response -->
77
+ <path d="M 510 360 L 310 360" class="response"/>
78
+ <text x="410" y="355" text-anchor="middle" class="text">FireDispatchMessage</text>
79
+
80
+ <!-- 4a. Crime/Security dispatch -->
81
+ <path d="M 310 400 L 680 400" class="message"/>
82
+ <text x="495" y="395" text-anchor="middle" class="text">Emergency911Message</text>
83
+ <text x="495" y="415" text-anchor="middle" class="note">(crime/security)</text>
84
+
85
+ <!-- 4b. Police response -->
86
+ <path d="M 680 440 L 310 440" class="response"/>
87
+ <text x="495" y="435" text-anchor="middle" class="text">PoliceDispatchMessage</text>
88
+
89
+ <!-- Call tracking note -->
90
+ <rect x="240" y="480" width="140" height="40" fill="#2a2a2a" stroke="#4a9eff" rx="4"/>
91
+ <text x="310" y="495" text-anchor="middle" class="note">Call tracking &amp;</text>
92
+ <text x="310" y="510" text-anchor="middle" class="note">statistics maintained</text>
93
+
94
+ <!-- Legend -->
95
+ <rect x="50" y="520" width="690" height="60" fill="#1a1a1a" stroke="#666" rx="6"/>
96
+ <text x="70" y="540" class="text">Key Message Types:</text>
97
+ <text x="70" y="560" class="text">Emergency911Message: Citizen reports • FireEmergencyMessage: Fire incidents</text>
98
+ <text x="70" y="575" class="text">FireDispatchMessage: Equipment deployment • PoliceDispatchMessage: Unit coordination</text>
99
+ </svg>
@@ -0,0 +1,515 @@
1
+ # SmartMessage City Emergency Services Demo
2
+
3
+ This comprehensive demo showcases a complete city emergency services communication system built with SmartMessage. It demonstrates real-world scenarios including emergency response coordination, health monitoring, and AI-powered incident reporting.
4
+
5
+ ## 🏙️ City Scenario Overview
6
+
7
+ The demo simulates a city emergency services network with multiple independent services that communicate through a Redis pub/sub messaging system. Each service operates autonomously but coordinates with others through standardized message protocols.
8
+
9
+ ### 🏢 City Services
10
+
11
+ | Service | Program File | Purpose | Key Features |
12
+ |---------|-------------|---------|--------------|
13
+ | **Emergency Dispatch Center** | `emergency_dispatch_center.rb` | 911 call routing and coordination | Call triage, department dispatch, call tracking |
14
+ | **Citizen** | `citizen.rb` | 911 emergency call simulation | Realistic emergency scenarios, automatic/manual calling |
15
+ | **Fire Department** | `fire_department.rb` | Fire emergency response coordination | Fire engine dispatch, equipment deployment |
16
+ | **Police Department** | `police_department.rb` | Law enforcement and security response | Unit assignment, crime response, alarm handling |
17
+ | **Local Bank** | `local_bank.rb` | Banking security monitoring | Silent alarm system, robbery detection |
18
+ | **Residential House** | `house.rb` | Fire safety monitoring | Smoke detection, resident safety alerts |
19
+ | **Health Department** | `health_department.rb` | City services health monitoring | Service status tracking, COVID-19 protocols |
20
+ | **Smart Visitor** | `visitor.rb` | AI-powered incident reporting | Emergency report generation, message selection |
21
+ | **Redis Monitor** | `redis_monitor.rb` | Real-time message monitoring | Live message traffic visualization |
22
+ | **Redis Stats** | `redis_stats.rb` | Performance analytics dashboard | Pub/sub statistics, throughput analysis |
23
+
24
+ ## 📨 Message Types
25
+
26
+ The city uses 8 standardized message types for emergency communication:
27
+
28
+ ### Emergency Messages
29
+ - **📞 Emergency911Message** - Citizen calls to 911 dispatch center
30
+ - **🔥 FireEmergencyMessage** - Fire alerts from houses or 911 to Fire Department
31
+ - **🚨 SilentAlarmMessage** - Security breaches from banks to Police Department
32
+ - **👮 PoliceDispatchMessage** - Police unit coordination responses
33
+ - **🚒 FireDispatchMessage** - Fire suppression deployment responses
34
+
35
+ ### System Messages
36
+ - **✅ EmergencyResolvedMessage** - Incident closure notifications
37
+ - **💚 HealthCheckMessage** - Service availability monitoring (every 5 seconds)
38
+ - **📊 HealthStatusMessage** - Service condition responses
39
+
40
+ ## 🔄 System Architecture
41
+
42
+ ### Health Monitoring System
43
+ All city services implement a **countdown timer health system** that:
44
+ - Resets on each HealthCheckMessage received (10-second timeout)
45
+ - Triggers COVID-19 shutdown if no health check received
46
+ - Responds with HealthStatusMessage (green/yellow/red status)
47
+ - Replaces traditional circuit breaker patterns
48
+
49
+ ### AI-Powered Incident Reporting
50
+ The Visitor service uses RubyLLM for intelligent incident reporting:
51
+ - Dynamically discovers available message types
52
+ - AI selects appropriate message format for incidents
53
+ - AI generates realistic property values
54
+ - Comprehensive logging of AI interactions
55
+
56
+ ## 📊 Message Flow Diagrams
57
+
58
+ ### 1. 911 Emergency Call Flow
59
+
60
+ ![911 Emergency Call Flow](911_emergency_call_flow.svg)
61
+
62
+ ### 2. Fire Emergency Flow
63
+
64
+ ![Fire Emergency Flow](fire_emergency_flow.svg)
65
+
66
+ ### 3. Security Emergency Flow
67
+
68
+ ![Security Emergency Flow](security_emergency_flow.svg)
69
+
70
+ ### 4. AI Visitor Intelligence Flow
71
+
72
+ ![AI Visitor Intelligence Flow](ai_visitor_intelligence_flow.svg)
73
+
74
+ ### Health Monitoring System
75
+
76
+ ![Health Monitoring System](health_monitoring_system.svg)
77
+
78
+ ### 5. Service Internal Architecture
79
+
80
+ ![Service Internal Architecture](service_internal_architecture.svg)
81
+
82
+ ## 🚀 Getting Started
83
+
84
+ ### Prerequisites
85
+ - **macOS** (required for start_demo.sh/stop_demo.sh scripts)
86
+ - **iTerm2** terminal emulator (for automated demo startup)
87
+ - Ruby 2.7 or higher
88
+ - Redis server
89
+ - RubyLLM gem with AI provider credentials (OpenAI, Anthropic, etc.)
90
+ - SmartMessage gem
91
+
92
+ ### Installation
93
+ ```bash
94
+ # Install iTerm2 (macOS only)
95
+ brew install --cask iterm2
96
+
97
+ # Install Redis
98
+ brew install redis
99
+ brew services start redis
100
+
101
+ # Install dependencies
102
+ bundle install
103
+
104
+ # Set up AI credentials (optional - fallback logic available)
105
+ export OPENAI_API_KEY="your-key-here"
106
+ export ANTHROPIC_API_KEY="your-key-here"
107
+ ```
108
+
109
+ ### Quick Start (macOS + iTerm2)
110
+ ```bash
111
+ # Make scripts executable
112
+ chmod +x start_demo.sh stop_demo.sh
113
+
114
+ # Start all services in iTerm2 (macOS only)
115
+ ./start_demo.sh
116
+
117
+ # Stop all services and close iTerm2 window (macOS only)
118
+ ./stop_demo.sh
119
+ ```
120
+
121
+ ### Manual Start (Cross-Platform)
122
+ For non-macOS systems or when not using iTerm2:
123
+ ```bash
124
+ # Terminal 1 - Health monitoring
125
+ ruby health_department.rb
126
+
127
+ # Terminal 2 - Emergency dispatch center (911)
128
+ ruby emergency_dispatch_center.rb
129
+
130
+ # Terminal 3 - Emergency services
131
+ ruby fire_department.rb
132
+
133
+ # Terminal 4 - Law enforcement
134
+ ruby police_department.rb
135
+
136
+ # Terminal 5 - Banking security
137
+ ruby local_bank.rb
138
+
139
+ # Terminal 6 - Residential monitoring
140
+ ruby house.rb
141
+
142
+ # Terminal 7 - Citizen 911 caller (optional)
143
+ ruby citizen.rb
144
+
145
+ # Terminal 8 - AI visitor (optional)
146
+ ruby visitor.rb
147
+
148
+ # Terminal 9 - Message monitoring (optional)
149
+ ruby redis_monitor.rb
150
+
151
+ # Terminal 10 - Performance analytics (optional)
152
+ ruby redis_stats.rb
153
+ ```
154
+
155
+ ## 🎭 Demo Scenarios
156
+
157
+ ### 📞 911 Emergency Call Scenario
158
+ 1. **Citizen witnesses emergency** → Generates Emergency911Message with random scenario
159
+ 2. **911 Dispatch Center receives call** → Analyzes emergency type and severity
160
+ 3. **Call routing** → Dispatches to appropriate departments (Fire/Police)
161
+ 4. **Department response** → Services respond with dispatch messages
162
+ 5. **Call tracking** → Statistics maintained until resolution
163
+
164
+ ### 🔥 Fire Emergency Scenario
165
+ 1. **House detects smoke** → Publishes FireEmergencyMessage
166
+ 2. **Fire Department responds** → Analyzes severity, dispatches equipment
167
+ 3. **Incident resolution** → Publishes EmergencyResolvedMessage
168
+
169
+ ### 🚨 Security Emergency Scenario
170
+ 1. **Bank detects robbery** → Publishes SilentAlarmMessage
171
+ 2. **Police Department responds** → Assigns units, coordinates response
172
+ 3. **Incident resolved** → Publishes EmergencyResolvedMessage
173
+
174
+ ### 🤖 AI-Powered Visitor Reporting
175
+ 1. **Visitor witnesses incident** → Analyzes available message types
176
+ 2. **AI selects appropriate message** → SilentAlarmMessage for robbery
177
+ 3. **AI generates properties** → Realistic bank name, location, details
178
+ 4. **Message published** → Emergency services receive report
179
+
180
+ ### 💚 Health Monitoring Scenario
181
+ 1. **Health Department broadcasts** → HealthCheckMessage every 5 seconds
182
+ 2. **All services respond** → HealthStatusMessage with current status
183
+ 3. **Timeout handling** → Services shut down after 10 seconds without health check
184
+
185
+ ## 📋 Service Details
186
+
187
+ ### Emergency Dispatch Center (`emergency_dispatch_center.rb`)
188
+ ```ruby
189
+ # 911 emergency call coordination hub
190
+ - Subscribes to: Emergency911Message (to: '911')
191
+ - Publishes: FireEmergencyMessage, Emergency911Message (routed)
192
+ - Call analysis: Determines which departments to dispatch
193
+ - Call tracking: Maintains active call registry with timestamps
194
+ - Statistics: Tracks calls by type and department dispatches
195
+ - Routing rules: Fire/Medical → Fire Dept, Crime/Security → Police
196
+ ```
197
+
198
+ ### Citizen (`citizen.rb`)
199
+ ```ruby
200
+ # 911 emergency call simulation system
201
+ - Publishes: Emergency911Message (to: '911')
202
+ - Emergency scenarios: 15+ realistic emergency types
203
+ - Types: fire, medical, crime, accident, hazmat, rescue, other
204
+ - Modes: Interactive (press Enter) or Automatic (15-30 sec intervals)
205
+ - Realistic data: Random caller names, phone numbers, locations
206
+ - Severity levels: critical, high, medium, low
207
+ ```
208
+
209
+ ### Fire Department (`fire_department.rb`)
210
+ ```ruby
211
+ # Handles fire emergencies with equipment dispatch
212
+ - Subscribes to: FireEmergencyMessage, Emergency911Message, HealthCheckMessage
213
+ - Publishes: FireDispatchMessage, HealthStatusMessage, EmergencyResolvedMessage
214
+ - Equipment: Engine-1, Ladder-1, Rescue-1, Hazmat-1
215
+ - Response time: 3-8 minutes based on severity
216
+ ```
217
+
218
+ ### Police Department (`police_department.rb`)
219
+ ```ruby
220
+ # Coordinates law enforcement response
221
+ - Subscribes to: SilentAlarmMessage, Emergency911Message, HealthCheckMessage
222
+ - Publishes: PoliceDispatchMessage, HealthStatusMessage, EmergencyResolvedMessage
223
+ - Units: Unit-101, Unit-102, Unit-103, Detective-1, SWAT-Alpha
224
+ - Priority levels: routine, urgent, emergency, critical
225
+ ```
226
+
227
+ ### Smart Visitor (`visitor.rb`)
228
+ ```ruby
229
+ # AI-powered incident reporting system
230
+ - Dynamic message type discovery
231
+ - RubyLLM integration for intelligent selection
232
+ - Comprehensive AI interaction logging
233
+ - Fallback logic when AI unavailable
234
+ - Realistic data generation
235
+ ```
236
+
237
+ ### Redis Monitor (`redis_monitor.rb`)
238
+ ```ruby
239
+ # Real-time message traffic visualization
240
+ - Subscribes to: All Redis channels (wildcard pattern)
241
+ - Live message stream display with color coding
242
+ - Message type-specific payload formatting
243
+ - Timestamp and routing information
244
+ - Emergency/health message categorization
245
+ ```
246
+
247
+ ### Redis Stats (`redis_stats.rb`)
248
+ ```ruby
249
+ # Comprehensive performance analytics dashboard
250
+ - Real-time pub/sub statistics
251
+ - Message throughput analysis (messages/sec)
252
+ - Channel activity monitoring
253
+ - Command performance metrics
254
+ - Interactive controls (q=quit, r=refresh, +/-=rate)
255
+ - Terminal-optimized full-screen display
256
+ ```
257
+
258
+ ## 🛠️ Configuration
259
+
260
+ ### Health Monitoring
261
+ ```ruby
262
+ # Customize health check interval (default: 5 seconds)
263
+ HEALTH_CHECK_INTERVAL = 5
264
+
265
+ # Customize service timeout (default: 10 seconds)
266
+ SERVICE_TIMEOUT = 10
267
+ ```
268
+
269
+ ### AI Configuration
270
+ ```ruby
271
+ # Configure RubyLLM providers
272
+ RubyLLM.configure do |config|
273
+ config.openai_api_key = ENV['OPENAI_API_KEY']
274
+ config.anthropic_api_key = ENV['ANTHROPIC_API_KEY']
275
+ config.log_level = :info
276
+ end
277
+ ```
278
+
279
+ ### Redis Transport
280
+ ```ruby
281
+ # Customize Redis connection
282
+ SmartMessage.configure do |config|
283
+ config.transport = SmartMessage::Transport::RedisTransport.new(
284
+ host: 'localhost',
285
+ port: 6379,
286
+ db: 0
287
+ )
288
+ end
289
+ ```
290
+
291
+ ## 📊 Monitoring and Observability
292
+
293
+ ### Real-Time Monitoring Tools
294
+
295
+ #### 🔍 Redis Monitor (`redis_monitor.rb`)
296
+ Live message stream monitoring with formatted output:
297
+
298
+ ```bash
299
+ ruby redis_monitor.rb
300
+ ```
301
+
302
+ **Features:**
303
+ - **Color-coded messages** by type (Health=Green, Emergency=Red, Dispatch=Blue)
304
+ - **Formatted payload display** showing relevant details for each message type
305
+ - **Real-time streaming** of all Redis pub/sub traffic
306
+ - **Message routing info** (from/to fields, timestamps)
307
+ - **Emergency context** (fire severity, police units, health status)
308
+
309
+ **Example Output:**
310
+ ```
311
+ 🔍 SmartMessage Redis Monitor
312
+ Monitoring Redis pub/sub traffic...
313
+
314
+ [14:35:22] Messages::SilentAlarmMessage
315
+ 📤 From: local-bank
316
+ 📥 To: police-department
317
+ 🚨 First National Bank - robbery (high)
318
+ 📍 123 Main Street
319
+
320
+ [14:35:23] Messages::PoliceDispatchMessage
321
+ 📤 From: police-department
322
+ 📥 To: broadcast
323
+ 🚔 Units: Unit-101, Unit-102
324
+ 📍 Location: 123 Main Street
325
+ ⏱️ ETA: 3 minutes
326
+ ```
327
+
328
+ #### 📈 Redis Stats (`redis_stats.rb`)
329
+ Interactive performance analytics dashboard:
330
+
331
+ ```bash
332
+ ruby redis_stats.rb
333
+ ```
334
+
335
+ **Features:**
336
+ - **Full-screen terminal dashboard** with real-time updates
337
+ - **Pub/Sub statistics** (subscribers, channels, message rates)
338
+ - **Channel analytics** (top channels by volume, rates per channel)
339
+ - **Command performance** (Redis command statistics and latency)
340
+ - **Session tracking** (messages since start, peak rates)
341
+ - **Interactive controls** (keyboard shortcuts for navigation)
342
+
343
+ **Dashboard Sections:**
344
+ 1. **Pub/Sub Overview** - Total messages, active channels, rates
345
+ 2. **Channel Analytics** - Per-channel message counts and rates
346
+ 3. **Command Statistics** - Redis command performance metrics
347
+ 4. **Latency Metrics** - Response time analysis
348
+ 5. **System Health** - Memory usage, connected clients
349
+
350
+ **Keyboard Controls:**
351
+ - `q` / `Q` / `Esc` - Quit monitor
352
+ - `r` / `R` - Force refresh
353
+ - `+` - Increase refresh rate
354
+ - `-` - Decrease refresh rate
355
+ - `h` / `H` / `?` - Show help overlay
356
+
357
+ ### Service Logs
358
+ Each service maintains detailed logs:
359
+ - `health_department.log` - Health monitoring activities
360
+ - `fire_department.log` - Fire response coordination
361
+ - `police_department.log` - Law enforcement activities
362
+ - `visitor.log` - AI interaction details
363
+
364
+ ### Message Tracing
365
+ All messages include comprehensive headers:
366
+ ```json
367
+ {
368
+ "_sm_header": {
369
+ "uuid": "unique-message-id",
370
+ "message_class": "Messages::FireEmergencyMessage",
371
+ "published_at": "2025-08-22T04:29:27-05:00",
372
+ "publisher_pid": 12345,
373
+ "version": 1,
374
+ "from": "house-sensor-01",
375
+ "serializer": "SmartMessage::Serializer::Json"
376
+ },
377
+ "_sm_payload": {
378
+ "location": "123 Oak Street",
379
+ "fire_type": "electrical",
380
+ "severity": "high"
381
+ }
382
+ }
383
+ ```
384
+
385
+ ## 🔧 Development and Extensions
386
+
387
+ ### Adding New Services
388
+ 1. Create service class inheriting from appropriate base
389
+ 2. Implement health monitoring with countdown timer
390
+ 3. Define message subscriptions and handlers
391
+ 4. Add service to demo startup scripts
392
+
393
+ ### Custom Message Types
394
+ 1. Create message class in `messages/` directory
395
+ 2. Define properties with validation
396
+ 3. Add descriptions for AI discovery
397
+ 4. Implement handlers in relevant services
398
+
399
+ ### AI Enhancement
400
+ 1. Customize prompts in `visitor.rb`
401
+ 2. Add new incident types
402
+ 3. Enhance property generation logic
403
+ 4. Implement multi-step AI workflows
404
+
405
+ ## 🚨 Emergency Procedures
406
+
407
+ ### Service Recovery
408
+ If a service becomes unresponsive:
409
+ ```bash
410
+ # Check service status
411
+ ps aux | grep ruby
412
+
413
+ # Use monitoring tools to diagnose issues
414
+ ruby redis_monitor.rb # Watch live message flow
415
+ ruby redis_stats.rb # Check performance metrics
416
+
417
+ # Restart specific service
418
+ ruby fire_department.rb
419
+
420
+ # Full system restart (macOS with iTerm2)
421
+ ./stop_demo.sh && ./start_demo.sh
422
+ ```
423
+
424
+ ### Health System Reset
425
+ ```bash
426
+ # Reset all service health timers
427
+ redis-cli FLUSHDB
428
+
429
+ # Monitor health recovery in real-time
430
+ ruby redis_monitor.rb & # Background monitoring
431
+ ruby health_department.rb
432
+ ```
433
+
434
+ ### Troubleshooting with Monitoring Tools
435
+
436
+ #### Message Flow Issues
437
+ ```bash
438
+ # Watch live message traffic to identify bottlenecks
439
+ ruby redis_monitor.rb
440
+
441
+ # Look for missing message types or routing problems
442
+ # Check if health checks are flowing properly
443
+ # Verify emergency messages reach appropriate services
444
+ ```
445
+
446
+ #### Performance Analysis
447
+ ```bash
448
+ # Launch interactive performance dashboard
449
+ ruby redis_stats.rb
450
+
451
+ # Monitor for:
452
+ # - High message rates that might overwhelm services
453
+ # - Channel imbalances (some channels too busy/idle)
454
+ # - Redis command performance issues
455
+ # - Memory usage spikes
456
+ ```
457
+
458
+ #### Platform-Specific Issues
459
+
460
+ **macOS with iTerm2:**
461
+ ```bash
462
+ # If start_demo.sh fails to open iTerm2
463
+ # Ensure iTerm2 is installed and in Applications folder
464
+ brew install --cask iterm2
465
+
466
+ # If demo window doesn't close properly
467
+ ./stop_demo.sh
468
+ # Or manually: pkill -f "ruby.*\.rb"
469
+ ```
470
+
471
+ **Cross-Platform Manual Start:**
472
+ ```bash
473
+ # If automated scripts don't work on your platform
474
+ # Use manual start approach with individual terminals
475
+ # All programs work on any Ruby-supported platform
476
+ ```
477
+
478
+ ## 📈 Performance Metrics
479
+
480
+ The demo tracks various performance metrics:
481
+ - Message throughput (messages/second)
482
+ - Response times (service-to-service)
483
+ - AI processing times
484
+ - Health check compliance rates
485
+ - Emergency response coordination times
486
+
487
+ ## 🎯 Real-World Applications
488
+
489
+ This demo architecture demonstrates patterns applicable to:
490
+ - **Emergency Services Coordination**
491
+ - **IoT Device Management**
492
+ - **Microservices Communication**
493
+ - **Event-Driven Architecture**
494
+ - **AI-Powered System Integration**
495
+ - **Health Monitoring Systems**
496
+
497
+ ## 📚 Further Reading
498
+
499
+ - [SmartMessage Documentation](../README.md)
500
+ - [Message Filtering Guide](../../docs/message_filtering.md)
501
+ - [Transport Configuration](../../docs/transports.md)
502
+ - [AI Integration Patterns](../../docs/ai_integration.md)
503
+
504
+ ## 🤝 Contributing
505
+
506
+ This demo welcomes contributions:
507
+ 1. Fork the repository
508
+ 2. Create feature branch
509
+ 3. Add new services or scenarios
510
+ 4. Test with existing city infrastructure
511
+ 5. Submit pull request with detailed description
512
+
513
+ ---
514
+
515
+ *The SmartMessage City Emergency Services Demo - Demonstrating real-world distributed system communication with AI-powered intelligence and comprehensive health monitoring.*