smart_message 0.0.10 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) 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 +64 -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} +80 -145
  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} +103 -89
  32. data/docs/{getting-started.md → getting-started/quick-start.md} +47 -23
  33. data/docs/index.md +64 -0
  34. data/docs/{dead_letter_queue.md → reference/dead-letter-queue.md} +2 -3
  35. data/docs/{logging.md → reference/logging.md} +1 -1
  36. data/docs/{message_deduplication.md → reference/message-deduplication.md} +1 -0
  37. data/docs/{proc_handlers_summary.md → reference/proc-handlers.md} +7 -6
  38. data/docs/reference/serializers.md +245 -0
  39. data/docs/{transports.md → reference/transports.md} +9 -11
  40. data/docs/transports/memory-transport.md +374 -0
  41. data/docs/transports/redis-transport-comparison.md +361 -0
  42. data/docs/transports/redis-transport.md +490 -0
  43. data/examples/README.md +104 -14
  44. data/examples/city_scenario/911_emergency_call_flow.svg +99 -0
  45. data/examples/city_scenario/README.md +515 -0
  46. data/examples/city_scenario/ai_visitor_intelligence_flow.svg +108 -0
  47. data/examples/city_scenario/citizen.rb +195 -0
  48. data/examples/city_scenario/city_diagram.svg +125 -0
  49. data/examples/city_scenario/common/health_monitor.rb +80 -0
  50. data/examples/city_scenario/common/logger.rb +30 -0
  51. data/examples/city_scenario/emergency_dispatch_center.rb +270 -0
  52. data/examples/city_scenario/fire_department.rb +446 -0
  53. data/examples/city_scenario/fire_emergency_flow.svg +95 -0
  54. data/examples/city_scenario/health_department.rb +100 -0
  55. data/examples/city_scenario/health_monitoring_system.svg +130 -0
  56. data/examples/city_scenario/house.rb +244 -0
  57. data/examples/city_scenario/local_bank.rb +217 -0
  58. data/examples/city_scenario/messages/emergency_911_message.rb +80 -0
  59. data/examples/city_scenario/messages/emergency_resolved_message.rb +42 -0
  60. data/examples/city_scenario/messages/fire_dispatch_message.rb +42 -0
  61. data/examples/city_scenario/messages/fire_emergency_message.rb +44 -0
  62. data/examples/city_scenario/messages/health_check_message.rb +21 -0
  63. data/examples/city_scenario/messages/health_status_message.rb +34 -0
  64. data/examples/city_scenario/messages/police_dispatch_message.rb +45 -0
  65. data/examples/city_scenario/messages/silent_alarm_message.rb +37 -0
  66. data/examples/city_scenario/police_department.rb +316 -0
  67. data/examples/city_scenario/redis_monitor.rb +129 -0
  68. data/examples/city_scenario/redis_stats.rb +743 -0
  69. data/examples/city_scenario/room_for_improvement.md +240 -0
  70. data/examples/city_scenario/security_emergency_flow.svg +95 -0
  71. data/examples/city_scenario/service_internal_architecture.svg +154 -0
  72. data/examples/city_scenario/smart_message_ai_agent.rb +364 -0
  73. data/examples/city_scenario/start_demo.sh +236 -0
  74. data/examples/city_scenario/stop_demo.sh +106 -0
  75. data/examples/city_scenario/visitor.rb +631 -0
  76. data/examples/{10_message_deduplication.rb → memory/01_message_deduplication_demo.rb} +1 -3
  77. data/examples/{09_dead_letter_queue_demo.rb → memory/02_dead_letter_queue_demo.rb} +10 -40
  78. data/examples/{01_point_to_point_orders.rb → memory/03_point_to_point_orders.rb} +1 -3
  79. data/examples/{02_publish_subscribe_events.rb → memory/04_publish_subscribe_events.rb} +1 -2
  80. data/examples/{03_many_to_many_chat.rb → memory/05_many_to_many_chat.rb} +1 -4
  81. data/examples/{show_me.rb → memory/06_pretty_print_demo.rb} +1 -1
  82. data/examples/{05_proc_handlers.rb → memory/07_proc_handlers_demo.rb} +1 -2
  83. data/examples/{06_custom_logger_example.rb → memory/08_custom_logger_demo.rb} +13 -14
  84. data/examples/{07_error_handling_scenarios.rb → memory/09_error_handling_demo.rb} +1 -4
  85. data/examples/{08_entity_addressing_basic.rb → memory/10_entity_addressing_basic.rb} +2 -8
  86. data/examples/{08_entity_addressing_with_filtering.rb → memory/11_entity_addressing_with_filtering.rb} +2 -6
  87. data/examples/{09_regex_filtering_microservices.rb → memory/12_regex_filtering_microservices.rb} +1 -2
  88. data/examples/{10_header_block_configuration.rb → memory/13_header_block_configuration.rb} +1 -6
  89. data/examples/{11_global_configuration_example.rb → memory/14_global_configuration_demo.rb} +17 -8
  90. data/examples/{show_logger.rb → memory/15_logger_demo.rb} +1 -2
  91. data/examples/memory/README.md +163 -0
  92. data/examples/memory/memory_transport_architecture.svg +90 -0
  93. data/examples/memory/point_to_point_pattern.svg +94 -0
  94. data/examples/memory/publish_subscribe_pattern.svg +125 -0
  95. data/examples/{04_redis_smart_home_iot.rb → redis/01_smart_home_iot_demo.rb} +1 -5
  96. data/examples/redis/README.md +228 -0
  97. data/examples/redis/alert_system_flow.svg +127 -0
  98. data/examples/redis/dashboard_status_flow.svg +107 -0
  99. data/examples/redis/device_command_flow.svg +113 -0
  100. data/examples/redis/redis_transport_architecture.svg +115 -0
  101. data/examples/{smart_home_iot_dataflow.md → redis/smart_home_iot_dataflow.md} +4 -116
  102. data/examples/redis/smart_home_system_architecture.svg +133 -0
  103. data/ideas/README.md +41 -0
  104. data/ideas/agents.md +1001 -0
  105. data/ideas/database_transport.md +980 -0
  106. data/ideas/improvement.md +359 -0
  107. data/ideas/meshage.md +1788 -0
  108. data/ideas/message_discovery.md +178 -0
  109. data/ideas/message_schema.md +1381 -0
  110. data/lib/smart_message/.idea/.gitignore +8 -0
  111. data/lib/smart_message/.idea/markdown.xml +6 -0
  112. data/lib/smart_message/.idea/misc.xml +4 -0
  113. data/lib/smart_message/.idea/modules.xml +8 -0
  114. data/lib/smart_message/.idea/smart_message.iml +16 -0
  115. data/lib/smart_message/.idea/vcs.xml +6 -0
  116. data/lib/smart_message/addressing.rb +15 -0
  117. data/lib/smart_message/base.rb +19 -12
  118. data/lib/smart_message/configuration.rb +2 -23
  119. data/lib/smart_message/dead_letter_queue.rb +1 -1
  120. data/lib/smart_message/logger.rb +15 -4
  121. data/lib/smart_message/messaging.rb +3 -62
  122. data/lib/smart_message/plugins.rb +6 -44
  123. data/lib/smart_message/serializer.rb +14 -0
  124. data/lib/smart_message/transport/base.rb +42 -8
  125. data/lib/smart_message/transport/memory_transport.rb +23 -4
  126. data/lib/smart_message/transport/redis_transport.rb +11 -0
  127. data/lib/smart_message/transport/stdout_transport.rb +28 -10
  128. data/lib/smart_message/transport.rb +33 -1
  129. data/lib/smart_message/version.rb +1 -1
  130. data/lib/smart_message.rb +5 -52
  131. data/mkdocs.yml +184 -0
  132. data/p2p_plan.md +326 -0
  133. data/p2p_roadmap.md +287 -0
  134. data/smart_message.gemspec +2 -0
  135. data/smart_message.svg +51 -0
  136. metadata +145 -45
  137. data/docs/README.md +0 -57
  138. data/docs/serializers.md +0 -575
  139. data/examples/dead_letters.jsonl +0 -12
  140. data/examples/temp.txt +0 -94
  141. data/examples/tmux_chat/README.md +0 -283
  142. data/examples/tmux_chat/bot_agent.rb +0 -278
  143. data/examples/tmux_chat/human_agent.rb +0 -199
  144. data/examples/tmux_chat/room_monitor.rb +0 -160
  145. data/examples/tmux_chat/shared_chat_system.rb +0 -328
  146. data/examples/tmux_chat/start_chat_demo.sh +0 -190
  147. data/examples/tmux_chat/stop_chat_demo.sh +0 -22
  148. /data/docs/{properties.md → core-concepts/properties.md} +0 -0
  149. /data/docs/{ideas_to_think_about.md → development/ideas.md} +0 -0
@@ -0,0 +1,361 @@
1
+ # Transport Comparison
2
+
3
+ SmartMessage provides multiple transport layers, each designed for different use cases and requirements. This document provides a comprehensive comparison to help you choose the right transport for your application.
4
+
5
+ ## Transport Overview
6
+
7
+ | Transport | Type | Best For | Key Feature |
8
+ |-----------|------|----------|-------------|
9
+ | **Memory** | In-Memory Queue | Testing, development | No external dependencies, fast |
10
+ | **STDOUT** | Logging/Debug | Development, debugging | Human-readable output |
11
+ | **Redis** | Pub/Sub | Production messaging | Distributed, persistent connections |
12
+
13
+ ---
14
+
15
+ ## 🧠 Memory Transport
16
+
17
+ Perfect for development, testing, and in-memory message queuing.
18
+
19
+ ### Architecture
20
+ ```
21
+ Publisher → Memory Queue → Subscriber
22
+ (thread-safe) (auto-processing)
23
+ ```
24
+
25
+ ### Key Characteristics
26
+ - **Message Persistence**: In-memory only - lost on restart
27
+ - **Pattern Support**: None - direct message class routing
28
+ - **Load Balancing**: No - all subscribers receive all messages
29
+ - **Threading**: Thread-safe with mutex protection
30
+ - **External Dependencies**: None
31
+
32
+ ### Configuration
33
+ ```ruby
34
+ SmartMessage::Transport.create(:memory,
35
+ auto_process: true, # Automatically route messages to dispatcher
36
+ max_messages: 1000 # Maximum messages to store in memory
37
+ )
38
+ ```
39
+
40
+ ### Use Cases
41
+ - **Unit testing** - Predictable, isolated environment
42
+ - **Development** - Quick setup without external services
43
+ - **In-memory queuing** - Fast processing without persistence
44
+ - **Message inspection** - Easy access to all stored messages
45
+
46
+ ### Pros
47
+ - ✅ No external dependencies
48
+ - ✅ Fastest performance (no serialization)
49
+ - ✅ Thread-safe operations
50
+ - ✅ Message inspection capabilities
51
+ - ✅ Memory overflow protection
52
+
53
+ ### Cons
54
+ - ❌ Messages lost on restart
55
+ - ❌ Single-process only
56
+ - ❌ Memory usage grows with message volume
57
+ - ❌ No network distribution
58
+
59
+ ### Example
60
+ ```ruby
61
+ class TestMessage < SmartMessage::Base
62
+ property :data
63
+
64
+ config do
65
+ transport SmartMessage::Transport.create(:memory, auto_process: true)
66
+ end
67
+
68
+ def self.process(decoded_message)
69
+ puts "Processing: #{decoded_message.data}"
70
+ end
71
+ end
72
+
73
+ TestMessage.subscribe
74
+ TestMessage.new(data: "Hello World").publish
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 📄 STDOUT Transport
80
+
81
+ Ideal for development, debugging, and logging scenarios.
82
+
83
+ ### Architecture
84
+ ```
85
+ Publisher → Console/File Output → Optional Loopback → Subscriber
86
+ (JSON formatting) (if enabled) (local processing)
87
+ ```
88
+
89
+ ### Key Characteristics
90
+ - **Message Persistence**: File-based if output specified
91
+ - **Pattern Support**: None - logging/debugging focused
92
+ - **Load Balancing**: No - single output destination
93
+ - **Threading**: Thread-safe file operations
94
+ - **External Dependencies**: None
95
+
96
+ ### Configuration
97
+ ```ruby
98
+ SmartMessage::Transport.create(:stdout,
99
+ loopback: true, # Process messages locally
100
+ output: "messages.log" # Output to file instead of console
101
+ )
102
+ ```
103
+
104
+ ### Use Cases
105
+ - **Development debugging** - See messages in real-time
106
+ - **Application logging** - Structured message logging
107
+ - **Message tracing** - Track message flow through system
108
+ - **Integration testing** - Verify message content
109
+
110
+ ### Pros
111
+ - ✅ Human-readable JSON output
112
+ - ✅ File-based persistence option
113
+ - ✅ Optional loopback for testing
114
+ - ✅ No external dependencies
115
+ - ✅ Structured message formatting
116
+
117
+ ### Cons
118
+ - ❌ Not suitable for production messaging
119
+ - ❌ Single output destination
120
+ - ❌ No network distribution
121
+ - ❌ Limited throughput for high-volume scenarios
122
+
123
+ ### Example
124
+ ```ruby
125
+ class LogMessage < SmartMessage::Base
126
+ property :level
127
+ property :message
128
+ property :timestamp, default: -> { Time.now.iso8601 }
129
+
130
+ config do
131
+ transport SmartMessage::Transport.create(:stdout,
132
+ output: "app.log",
133
+ loopback: false
134
+ )
135
+ end
136
+ end
137
+
138
+ LogMessage.new(level: "INFO", message: "Application started").publish
139
+ ```
140
+
141
+ ---
142
+
143
+ ## 🔴 Redis Transport
144
+
145
+ Production-ready Redis pub/sub transport for distributed messaging.
146
+
147
+ ### Architecture
148
+ ```
149
+ Publisher → Redis Channel → Subscriber
150
+ (pub/sub) (thread-based)
151
+ ```
152
+
153
+ ### Key Characteristics
154
+ - **Message Persistence**: No - fire-and-forget pub/sub
155
+ - **Pattern Support**: None - exact channel name matching
156
+ - **Load Balancing**: No - all subscribers receive all messages
157
+ - **Threading**: Traditional thread-per-subscriber model
158
+ - **External Dependencies**: Redis server
159
+
160
+ ### Configuration
161
+ ```ruby
162
+ SmartMessage::Transport.create(:redis,
163
+ url: 'redis://localhost:6379', # Redis connection URL
164
+ db: 0, # Redis database number
165
+ auto_subscribe: true, # Automatically start subscriber
166
+ reconnect_attempts: 5, # Connection retry attempts
167
+ reconnect_delay: 1 # Delay between retries (seconds)
168
+ )
169
+ ```
170
+
171
+ ### Use Cases
172
+ - **Production messaging** - Reliable distributed messaging
173
+ - **Microservices communication** - Service-to-service messaging
174
+ - **Real-time applications** - Low-latency message delivery
175
+ - **Scalable architectures** - Multiple publishers and subscribers
176
+
177
+ ### Pros
178
+ - ✅ Production-ready reliability
179
+ - ✅ Distributed messaging support
180
+ - ✅ Automatic reconnection handling
181
+ - ✅ Low latency (~1ms)
182
+ - ✅ High throughput (80K+ messages/second)
183
+ - ✅ Automatic serialization (MessagePack/JSON)
184
+
185
+ ### Cons
186
+ - ❌ Requires Redis server
187
+ - ❌ No message persistence
188
+ - ❌ No pattern-based routing
189
+ - ❌ No load balancing
190
+ - ❌ All subscribers receive all messages
191
+
192
+ ### Example
193
+ ```ruby
194
+ class OrderMessage < SmartMessage::Base
195
+ property :order_id
196
+ property :customer_id
197
+ property :amount
198
+
199
+ config do
200
+ transport SmartMessage::Transport.create(:redis,
201
+ url: ENV['REDIS_URL'] || 'redis://localhost:6379',
202
+ db: 1
203
+ )
204
+ end
205
+
206
+ def self.process(decoded_message)
207
+ order = decoded_message
208
+ puts "Processing order #{order.order_id} for $#{order.amount}"
209
+ end
210
+ end
211
+
212
+ OrderMessage.subscribe
213
+ OrderMessage.new(
214
+ order_id: "ORD-123",
215
+ customer_id: "CUST-456",
216
+ amount: 99.99
217
+ ).publish
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 📊 Feature Comparison Matrix
223
+
224
+ | Feature | Memory | STDOUT | Redis |
225
+ |---------|--------|--------|-------|
226
+ | **Message Persistence** | ❌ Memory Only | ✅ File Optional | ❌ No |
227
+ | **Network Distribution** | ❌ No | ❌ No | ✅ Yes |
228
+ | **External Dependencies** | ❌ None | ❌ None | ✅ Redis |
229
+ | **Pattern Matching** | ❌ No | ❌ No | ❌ No |
230
+ | **Load Balancing** | ❌ No | ❌ No | ❌ No |
231
+ | **Setup Complexity** | Easy | Easy | Medium |
232
+ | **Performance (Latency)** | ~0.1ms | ~1ms | ~1ms |
233
+ | **Performance (Throughput)** | Highest | Medium | High |
234
+ | **Serialization** | None | JSON | MessagePack/JSON |
235
+ | **Thread Safety** | ✅ Yes | ✅ Yes | ✅ Yes |
236
+ | **Message Inspection** | ✅ Yes | ✅ Yes | ❌ No |
237
+ | **Production Ready** | ❌ Testing Only | ❌ Logging Only | ✅ Yes |
238
+ | **Horizontal Scaling** | ❌ No | ❌ No | ✅ Yes |
239
+
240
+ ---
241
+
242
+ ## 🎯 Choosing the Right Transport
243
+
244
+ ### Use Memory Transport When:
245
+ - ✅ You're writing unit tests
246
+ - ✅ You're developing locally
247
+ - ✅ You need fast, in-memory message processing
248
+ - ✅ You want to inspect messages for testing
249
+ - ✅ You don't need persistence or distribution
250
+
251
+ ### Use STDOUT Transport When:
252
+ - ✅ You're debugging message flow
253
+ - ✅ You need human-readable message logging
254
+ - ✅ You're building development tools
255
+ - ✅ You want to trace messages in integration tests
256
+ - ✅ You need simple file-based message storage
257
+
258
+ ### Use Redis Transport When:
259
+ - ✅ You're building production applications
260
+ - ✅ You need distributed messaging
261
+ - ✅ You have microservices that need to communicate
262
+ - ✅ You need reliable, scalable messaging
263
+ - ✅ You can manage a Redis server dependency
264
+
265
+ ---
266
+
267
+ ## 🔄 Migration Patterns
268
+
269
+ ### Development → Production
270
+ ```ruby
271
+ # Development (Memory)
272
+ class MyMessage < SmartMessage::Base
273
+ config do
274
+ transport SmartMessage::Transport.create(:memory, auto_process: true)
275
+ end
276
+ end
277
+
278
+ # Production (Redis)
279
+ class MyMessage < SmartMessage::Base
280
+ config do
281
+ transport SmartMessage::Transport.create(:redis,
282
+ url: ENV['REDIS_URL'] || 'redis://localhost:6379'
283
+ )
284
+ end
285
+ end
286
+ ```
287
+
288
+ ### Environment-Based Configuration
289
+ ```ruby
290
+ class MyMessage < SmartMessage::Base
291
+ config do
292
+ transport case Rails.env
293
+ when 'test'
294
+ SmartMessage::Transport.create(:memory, auto_process: true)
295
+ when 'development'
296
+ SmartMessage::Transport.create(:stdout, loopback: true)
297
+ when 'production'
298
+ SmartMessage::Transport.create(:redis, url: ENV['REDIS_URL'])
299
+ end
300
+ end
301
+ end
302
+ ```
303
+
304
+ ---
305
+
306
+ ## 📈 Performance Characteristics
307
+
308
+ ### Latency Comparison
309
+ - **Memory**: ~0.1ms (fastest, no serialization)
310
+ - **STDOUT**: ~1ms (JSON formatting overhead)
311
+ - **Redis**: ~1ms (network + serialization)
312
+
313
+ ### Throughput Comparison
314
+ - **Memory**: Highest (limited by CPU and memory)
315
+ - **STDOUT**: Medium (limited by I/O operations)
316
+ - **Redis**: High (limited by network and Redis performance)
317
+
318
+ ### Memory Usage
319
+ - **Memory**: Grows with message volume (configurable limit)
320
+ - **STDOUT**: Minimal (immediate output/write)
321
+ - **Redis**: Low (messages not stored locally)
322
+
323
+ ---
324
+
325
+ ## 🛠️ Configuration Examples
326
+
327
+ ### Test Environment
328
+ ```ruby
329
+ SmartMessage.configure do |config|
330
+ config.default_transport = SmartMessage::Transport.create(:memory,
331
+ auto_process: true,
332
+ max_messages: 100
333
+ )
334
+ end
335
+ ```
336
+
337
+ ### Development Environment
338
+ ```ruby
339
+ SmartMessage.configure do |config|
340
+ config.default_transport = SmartMessage::Transport.create(:stdout,
341
+ loopback: true,
342
+ output: "log/messages.log"
343
+ )
344
+ end
345
+ ```
346
+
347
+ ### Production Environment
348
+ ```ruby
349
+ SmartMessage.configure do |config|
350
+ config.default_transport = SmartMessage::Transport.create(:redis,
351
+ url: ENV['REDIS_URL'],
352
+ db: ENV['REDIS_DB']&.to_i || 0,
353
+ reconnect_attempts: 10,
354
+ reconnect_delay: 2
355
+ )
356
+ end
357
+ ```
358
+
359
+ ---
360
+
361
+ This comparison should help you choose the right transport for your specific use case within the SmartMessage ecosystem. Each transport is optimized for different scenarios and provides the flexibility to grow your application from development to production.