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.
- checksums.yaml +4 -4
- data/.github/workflows/deploy-github-pages.yml +38 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile.lock +35 -4
- data/README.md +169 -71
- data/Rakefile +29 -4
- data/docs/assets/images/ddq_architecture.svg +130 -0
- data/docs/assets/images/dlq_architecture.svg +115 -0
- data/docs/assets/images/enhanced-dual-publishing.svg +136 -0
- data/docs/assets/images/enhanced-fluent-api.svg +149 -0
- data/docs/assets/images/enhanced-microservices-routing.svg +115 -0
- data/docs/assets/images/enhanced-pattern-matching.svg +107 -0
- data/docs/assets/images/fluent-api-demo.svg +59 -0
- data/docs/assets/images/performance-comparison.svg +161 -0
- data/docs/assets/images/redis-basic-architecture.svg +53 -0
- data/docs/assets/images/redis-enhanced-architecture.svg +88 -0
- data/docs/assets/images/redis-queue-architecture.svg +101 -0
- data/docs/assets/images/smart_message.jpg +0 -0
- data/docs/assets/images/smart_message_walking.jpg +0 -0
- data/docs/assets/images/smartmessage_architecture_overview.svg +173 -0
- data/docs/assets/images/transport-comparison-matrix.svg +171 -0
- data/docs/assets/javascripts/mathjax.js +17 -0
- data/docs/assets/stylesheets/extra.css +51 -0
- data/docs/{addressing.md → core-concepts/addressing.md} +5 -7
- data/docs/{architecture.md → core-concepts/architecture.md} +78 -138
- data/docs/{dispatcher.md → core-concepts/dispatcher.md} +21 -21
- data/docs/{message_filtering.md → core-concepts/message-filtering.md} +2 -3
- data/docs/{message_processing.md → core-concepts/message-processing.md} +17 -17
- data/docs/{troubleshooting.md → development/troubleshooting.md} +7 -7
- data/docs/{examples.md → getting-started/examples.md} +115 -89
- data/docs/{getting-started.md → getting-started/quick-start.md} +47 -18
- data/docs/guides/redis-queue-getting-started.md +697 -0
- data/docs/guides/redis-queue-patterns.md +889 -0
- data/docs/guides/redis-queue-production.md +1091 -0
- data/docs/index.md +64 -0
- data/docs/{dead_letter_queue.md → reference/dead-letter-queue.md} +2 -3
- data/docs/{logging.md → reference/logging.md} +1 -1
- data/docs/{message_deduplication.md → reference/message-deduplication.md} +1 -0
- data/docs/{proc_handlers_summary.md → reference/proc-handlers.md} +7 -6
- data/docs/{serializers.md → reference/serializers.md} +3 -5
- data/docs/{transports.md → reference/transports.md} +133 -11
- data/docs/transports/memory-transport.md +374 -0
- data/docs/transports/redis-enhanced-transport.md +524 -0
- data/docs/transports/redis-queue-transport.md +1304 -0
- data/docs/transports/redis-transport-comparison.md +496 -0
- data/docs/transports/redis-transport.md +509 -0
- data/examples/README.md +98 -5
- data/examples/city_scenario/911_emergency_call_flow.svg +99 -0
- data/examples/city_scenario/README.md +515 -0
- data/examples/city_scenario/ai_visitor_intelligence_flow.svg +108 -0
- data/examples/city_scenario/citizen.rb +195 -0
- data/examples/city_scenario/city_diagram.svg +125 -0
- data/examples/city_scenario/common/health_monitor.rb +80 -0
- data/examples/city_scenario/common/logger.rb +30 -0
- data/examples/city_scenario/emergency_dispatch_center.rb +270 -0
- data/examples/city_scenario/fire_department.rb +446 -0
- data/examples/city_scenario/fire_emergency_flow.svg +95 -0
- data/examples/city_scenario/health_department.rb +100 -0
- data/examples/city_scenario/health_monitoring_system.svg +130 -0
- data/examples/city_scenario/house.rb +244 -0
- data/examples/city_scenario/local_bank.rb +217 -0
- data/examples/city_scenario/messages/emergency_911_message.rb +81 -0
- data/examples/city_scenario/messages/emergency_resolved_message.rb +43 -0
- data/examples/city_scenario/messages/fire_dispatch_message.rb +43 -0
- data/examples/city_scenario/messages/fire_emergency_message.rb +45 -0
- data/examples/city_scenario/messages/health_check_message.rb +22 -0
- data/examples/city_scenario/messages/health_status_message.rb +35 -0
- data/examples/city_scenario/messages/police_dispatch_message.rb +46 -0
- data/examples/city_scenario/messages/silent_alarm_message.rb +38 -0
- data/examples/city_scenario/police_department.rb +316 -0
- data/examples/city_scenario/redis_monitor.rb +129 -0
- data/examples/city_scenario/redis_stats.rb +743 -0
- data/examples/city_scenario/room_for_improvement.md +240 -0
- data/examples/city_scenario/security_emergency_flow.svg +95 -0
- data/examples/city_scenario/service_internal_architecture.svg +154 -0
- data/examples/city_scenario/smart_message_ai_agent.rb +364 -0
- data/examples/city_scenario/start_demo.sh +236 -0
- data/examples/city_scenario/stop_demo.sh +106 -0
- data/examples/city_scenario/visitor.rb +631 -0
- data/examples/{10_message_deduplication.rb → memory/01_message_deduplication_demo.rb} +1 -1
- data/examples/{09_dead_letter_queue_demo.rb → memory/02_dead_letter_queue_demo.rb} +13 -40
- data/examples/{01_point_to_point_orders.rb → memory/03_point_to_point_orders.rb} +1 -1
- data/examples/{02_publish_subscribe_events.rb → memory/04_publish_subscribe_events.rb} +2 -2
- data/examples/{03_many_to_many_chat.rb → memory/05_many_to_many_chat.rb} +4 -4
- data/examples/{show_me.rb → memory/06_pretty_print_demo.rb} +1 -1
- data/examples/{05_proc_handlers.rb → memory/07_proc_handlers_demo.rb} +2 -2
- data/examples/{06_custom_logger_example.rb → memory/08_custom_logger_demo.rb} +17 -14
- data/examples/{07_error_handling_scenarios.rb → memory/09_error_handling_demo.rb} +4 -4
- data/examples/{08_entity_addressing_basic.rb → memory/10_entity_addressing_basic.rb} +8 -8
- data/examples/{08_entity_addressing_with_filtering.rb → memory/11_entity_addressing_with_filtering.rb} +6 -6
- data/examples/{09_regex_filtering_microservices.rb → memory/12_regex_filtering_microservices.rb} +2 -2
- data/examples/{10_header_block_configuration.rb → memory/13_header_block_configuration.rb} +6 -6
- data/examples/{11_global_configuration_example.rb → memory/14_global_configuration_demo.rb} +19 -8
- data/examples/{show_logger.rb → memory/15_logger_demo.rb} +1 -1
- data/examples/memory/README.md +163 -0
- data/examples/memory/memory_transport_architecture.svg +90 -0
- data/examples/memory/point_to_point_pattern.svg +94 -0
- data/examples/memory/publish_subscribe_pattern.svg +125 -0
- data/examples/{04_redis_smart_home_iot.rb → redis/01_smart_home_iot_demo.rb} +5 -5
- data/examples/redis/README.md +230 -0
- data/examples/redis/alert_system_flow.svg +127 -0
- data/examples/redis/dashboard_status_flow.svg +107 -0
- data/examples/redis/device_command_flow.svg +113 -0
- data/examples/redis/redis_transport_architecture.svg +115 -0
- data/examples/{smart_home_iot_dataflow.md → redis/smart_home_iot_dataflow.md} +4 -116
- data/examples/redis/smart_home_system_architecture.svg +133 -0
- data/examples/redis_enhanced/README.md +319 -0
- data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_enhanced/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/01_basic_messaging.rb +221 -0
- data/examples/redis_queue/01_comprehensive_examples.rb +508 -0
- data/examples/redis_queue/02_pattern_routing.rb +405 -0
- data/examples/redis_queue/03_fluent_api.rb +422 -0
- data/examples/redis_queue/04_load_balancing.rb +486 -0
- data/examples/redis_queue/05_microservices.rb +735 -0
- data/examples/redis_queue/06_emergency_alerts.rb +777 -0
- data/examples/redis_queue/07_queue_management.rb +587 -0
- data/examples/redis_queue/README.md +366 -0
- data/examples/redis_queue/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_queue/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_queue/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_queue/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/redis_queue_architecture.svg +148 -0
- data/ideas/README.md +41 -0
- data/ideas/agents.md +1001 -0
- data/ideas/database_transport.md +980 -0
- data/ideas/improvement.md +359 -0
- data/ideas/meshage.md +1788 -0
- data/ideas/message_discovery.md +178 -0
- data/ideas/message_schema.md +1381 -0
- data/lib/smart_message/.idea/.gitignore +8 -0
- data/lib/smart_message/.idea/markdown.xml +6 -0
- data/lib/smart_message/.idea/misc.xml +4 -0
- data/lib/smart_message/.idea/modules.xml +8 -0
- data/lib/smart_message/.idea/smart_message.iml +16 -0
- data/lib/smart_message/.idea/vcs.xml +6 -0
- data/lib/smart_message/addressing.rb +15 -0
- data/lib/smart_message/base.rb +0 -2
- data/lib/smart_message/configuration.rb +1 -1
- data/lib/smart_message/logger.rb +15 -4
- data/lib/smart_message/plugins.rb +5 -2
- data/lib/smart_message/serializer.rb +14 -0
- data/lib/smart_message/transport/redis_enhanced_transport.rb +399 -0
- data/lib/smart_message/transport/redis_queue_transport.rb +555 -0
- data/lib/smart_message/transport/registry.rb +1 -0
- data/lib/smart_message/transport.rb +34 -1
- data/lib/smart_message/version.rb +1 -1
- data/lib/smart_message.rb +5 -52
- data/mkdocs.yml +184 -0
- data/p2p_plan.md +326 -0
- data/p2p_roadmap.md +287 -0
- data/smart_message.gemspec +2 -0
- data/smart_message.svg +51 -0
- metadata +170 -44
- data/docs/README.md +0 -57
- data/examples/dead_letters.jsonl +0 -12
- data/examples/temp.txt +0 -94
- data/examples/tmux_chat/README.md +0 -283
- data/examples/tmux_chat/bot_agent.rb +0 -278
- data/examples/tmux_chat/human_agent.rb +0 -199
- data/examples/tmux_chat/room_monitor.rb +0 -160
- data/examples/tmux_chat/shared_chat_system.rb +0 -328
- data/examples/tmux_chat/start_chat_demo.sh +0 -190
- data/examples/tmux_chat/stop_chat_demo.sh +0 -22
- /data/docs/{properties.md → core-concepts/properties.md} +0 -0
- /data/docs/{ideas_to_think_about.md → development/ideas.md} +0 -0
@@ -0,0 +1,419 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# examples/redis_queue/enhanced_04_advanced_routing.rb
|
3
|
+
# Redis Enhanced Transport - Advanced Routing and Filtering Demo
|
4
|
+
|
5
|
+
require_relative '../../lib/smart_message'
|
6
|
+
require 'smart_message/transport/redis_enhanced_transport'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
puts "🚀 Redis Enhanced Transport - Advanced Routing Demo"
|
10
|
+
puts "=" * 53
|
11
|
+
|
12
|
+
# Create enhanced Redis transport
|
13
|
+
transport = SmartMessage::Transport::RedisEnhancedTransport.new(
|
14
|
+
url: 'redis://localhost:6379',
|
15
|
+
db: 5, # Use database 5 for advanced routing examples
|
16
|
+
auto_subscribe: true
|
17
|
+
)
|
18
|
+
|
19
|
+
#==============================================================================
|
20
|
+
# Define Complex Microservices Message Classes
|
21
|
+
#==============================================================================
|
22
|
+
|
23
|
+
class ApiRequestMessage < SmartMessage::Base
|
24
|
+
from 'api-gateway'
|
25
|
+
|
26
|
+
transport transport
|
27
|
+
serializer SmartMessage::Serializer::Json.new
|
28
|
+
|
29
|
+
property :request_id, required: true
|
30
|
+
property :endpoint, required: true
|
31
|
+
property :method, required: true
|
32
|
+
property :user_id
|
33
|
+
property :service_target, required: true
|
34
|
+
|
35
|
+
def self.process(wrapper)
|
36
|
+
header, payload = wrapper.split
|
37
|
+
data = JSON.parse(payload)
|
38
|
+
|
39
|
+
puts "🌐 [API GATEWAY] #{data['method']} #{data['endpoint']}"
|
40
|
+
puts " Request ID: #{data['request_id']}"
|
41
|
+
puts " Target: #{data['service_target']}"
|
42
|
+
puts " User: #{data['user_id'] || 'anonymous'}"
|
43
|
+
puts " Route: #{header.from} → #{header.to}"
|
44
|
+
puts
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class DatabaseQueryMessage < SmartMessage::Base
|
49
|
+
from 'orm-layer'
|
50
|
+
to 'database-service'
|
51
|
+
|
52
|
+
transport transport
|
53
|
+
serializer SmartMessage::Serializer::Json.new
|
54
|
+
|
55
|
+
property :query_id, required: true
|
56
|
+
property :query_type, required: true # SELECT, INSERT, UPDATE, DELETE
|
57
|
+
property :table, required: true
|
58
|
+
property :execution_time_ms
|
59
|
+
|
60
|
+
def self.process(wrapper)
|
61
|
+
header, payload = wrapper.split
|
62
|
+
data = JSON.parse(payload)
|
63
|
+
|
64
|
+
puts "🗄️ [DATABASE] #{data['query_type']} on #{data['table']}"
|
65
|
+
puts " Query ID: #{data['query_id']}"
|
66
|
+
puts " Execution: #{data['execution_time_ms']}ms"
|
67
|
+
puts " Route: #{header.from} → #{header.to}"
|
68
|
+
puts
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class LogMessage < SmartMessage::Base
|
73
|
+
from 'various-services'
|
74
|
+
to 'log-aggregator'
|
75
|
+
|
76
|
+
transport transport
|
77
|
+
serializer SmartMessage::Serializer::Json.new
|
78
|
+
|
79
|
+
property :log_id, required: true
|
80
|
+
property :level, required: true # DEBUG, INFO, WARN, ERROR, FATAL
|
81
|
+
property :service, required: true
|
82
|
+
property :message, required: true
|
83
|
+
property :context, default: {}
|
84
|
+
|
85
|
+
def self.process(wrapper)
|
86
|
+
header, payload = wrapper.split
|
87
|
+
data = JSON.parse(payload)
|
88
|
+
|
89
|
+
level_emoji = {
|
90
|
+
'DEBUG' => '🔍',
|
91
|
+
'INFO' => 'ℹ️',
|
92
|
+
'WARN' => '⚠️',
|
93
|
+
'ERROR' => '❌',
|
94
|
+
'FATAL' => '💀'
|
95
|
+
}[data['level']] || '📝'
|
96
|
+
|
97
|
+
puts "#{level_emoji} [LOG AGGREGATOR] #{data['level']} from #{data['service']}"
|
98
|
+
puts " #{data['message']}"
|
99
|
+
puts " Context: #{data['context']}" unless data['context'].empty?
|
100
|
+
puts " Route: #{header.from} → #{header.to}"
|
101
|
+
puts
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class MetricsMessage < SmartMessage::Base
|
106
|
+
from 'monitoring-agents'
|
107
|
+
to 'metrics-collector'
|
108
|
+
|
109
|
+
transport transport
|
110
|
+
serializer SmartMessage::Serializer::Json.new
|
111
|
+
|
112
|
+
property :metric_id, required: true
|
113
|
+
property :metric_name, required: true
|
114
|
+
property :value, required: true
|
115
|
+
property :tags, default: {}
|
116
|
+
property :timestamp, default: -> { Time.now.to_f }
|
117
|
+
|
118
|
+
def self.process(wrapper)
|
119
|
+
header, payload = wrapper.split
|
120
|
+
data = JSON.parse(payload)
|
121
|
+
|
122
|
+
puts "📊 [METRICS] #{data['metric_name']}: #{data['value']}"
|
123
|
+
puts " Tags: #{data['tags']}"
|
124
|
+
puts " From: #{header.from}"
|
125
|
+
puts
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
#==============================================================================
|
130
|
+
# Advanced Routing Demonstration Functions
|
131
|
+
#==============================================================================
|
132
|
+
|
133
|
+
def setup_service_specific_routing(transport)
|
134
|
+
puts "🎯 Setting up service-specific routing patterns..."
|
135
|
+
puts
|
136
|
+
|
137
|
+
# Route API requests to specific services
|
138
|
+
transport.where.from('api-gateway').to('user-service').subscribe
|
139
|
+
transport.where.from('api-gateway').to('order-service').subscribe
|
140
|
+
transport.where.from('api-gateway').to('payment-service').subscribe
|
141
|
+
|
142
|
+
puts "✅ API Gateway routing configured for:"
|
143
|
+
puts " • user-service"
|
144
|
+
puts " • order-service"
|
145
|
+
puts " • payment-service"
|
146
|
+
puts
|
147
|
+
|
148
|
+
# Database queries from different ORM layers
|
149
|
+
transport.where.from('user-orm').type('DatabaseQueryMessage').subscribe
|
150
|
+
transport.where.from('order-orm').type('DatabaseQueryMessage').subscribe
|
151
|
+
transport.where.from('analytics-orm').type('DatabaseQueryMessage').subscribe
|
152
|
+
|
153
|
+
puts "✅ Database query routing configured for:"
|
154
|
+
puts " • user-orm queries"
|
155
|
+
puts " • order-orm queries"
|
156
|
+
puts " • analytics-orm queries"
|
157
|
+
puts
|
158
|
+
end
|
159
|
+
|
160
|
+
def setup_log_level_filtering(transport)
|
161
|
+
puts "📋 Setting up log level filtering patterns..."
|
162
|
+
puts
|
163
|
+
|
164
|
+
# Different log processing based on level and service
|
165
|
+
transport.subscribe_pattern("logmessage.user_service.log_aggregator")
|
166
|
+
transport.subscribe_pattern("logmessage.payment_service.log_aggregator")
|
167
|
+
transport.subscribe_pattern("logmessage.critical_service.log_aggregator")
|
168
|
+
|
169
|
+
puts "✅ Log filtering configured for:"
|
170
|
+
puts " • user-service logs"
|
171
|
+
puts " • payment-service logs"
|
172
|
+
puts " • critical-service logs"
|
173
|
+
puts
|
174
|
+
end
|
175
|
+
|
176
|
+
def setup_metrics_collection_routing(transport)
|
177
|
+
puts "📈 Setting up metrics collection routing..."
|
178
|
+
puts
|
179
|
+
|
180
|
+
# Collect metrics from different monitoring agents
|
181
|
+
transport.where.type('MetricsMessage').from('cpu-monitor').subscribe
|
182
|
+
transport.where.type('MetricsMessage').from('memory-monitor').subscribe
|
183
|
+
transport.where.type('MetricsMessage').from('disk-monitor').subscribe
|
184
|
+
transport.where.type('MetricsMessage').from('network-monitor').subscribe
|
185
|
+
|
186
|
+
puts "✅ Metrics collection configured for:"
|
187
|
+
puts " • CPU monitoring"
|
188
|
+
puts " • Memory monitoring"
|
189
|
+
puts " • Disk monitoring"
|
190
|
+
puts " • Network monitoring"
|
191
|
+
puts
|
192
|
+
end
|
193
|
+
|
194
|
+
def demonstrate_dynamic_routing
|
195
|
+
puts "🔄 Demonstrating dynamic routing scenarios..."
|
196
|
+
puts
|
197
|
+
|
198
|
+
# Scenario 1: API Gateway routes to different services
|
199
|
+
api_requests = [
|
200
|
+
{ service: 'user-service', endpoint: '/users/profile', method: 'GET' },
|
201
|
+
{ service: 'order-service', endpoint: '/orders/create', method: 'POST' },
|
202
|
+
{ service: 'payment-service', endpoint: '/payments/process', method: 'POST' }
|
203
|
+
]
|
204
|
+
|
205
|
+
api_requests.each_with_index do |req, i|
|
206
|
+
message = ApiRequestMessage.new(
|
207
|
+
request_id: "REQ-#{Time.now.to_i}-#{i}",
|
208
|
+
endpoint: req[:endpoint],
|
209
|
+
method: req[:method],
|
210
|
+
service_target: req[:service],
|
211
|
+
user_id: "user_#{100 + i}"
|
212
|
+
)
|
213
|
+
message.to(req[:service]) # Dynamic routing
|
214
|
+
message.publish
|
215
|
+
|
216
|
+
sleep 0.1
|
217
|
+
end
|
218
|
+
|
219
|
+
puts "✅ Published 3 API requests with dynamic routing"
|
220
|
+
puts
|
221
|
+
end
|
222
|
+
|
223
|
+
def demonstrate_database_query_routing
|
224
|
+
puts "🗄️ Demonstrating database query routing..."
|
225
|
+
puts
|
226
|
+
|
227
|
+
queries = [
|
228
|
+
{ orm: 'user-orm', type: 'SELECT', table: 'users', time: 15 },
|
229
|
+
{ orm: 'order-orm', type: 'INSERT', table: 'orders', time: 8 },
|
230
|
+
{ orm: 'analytics-orm', type: 'UPDATE', table: 'metrics', time: 45 }
|
231
|
+
]
|
232
|
+
|
233
|
+
queries.each_with_index do |query, i|
|
234
|
+
message = DatabaseQueryMessage.new(
|
235
|
+
query_id: "QRY-#{Time.now.to_i}-#{i}",
|
236
|
+
query_type: query[:type],
|
237
|
+
table: query[:table],
|
238
|
+
execution_time_ms: query[:time]
|
239
|
+
)
|
240
|
+
message.from(query[:orm]) # Dynamic sender
|
241
|
+
message.publish
|
242
|
+
|
243
|
+
sleep 0.1
|
244
|
+
end
|
245
|
+
|
246
|
+
puts "✅ Published 3 database queries from different ORM layers"
|
247
|
+
puts
|
248
|
+
end
|
249
|
+
|
250
|
+
def demonstrate_log_aggregation_routing
|
251
|
+
puts "📋 Demonstrating log aggregation routing..."
|
252
|
+
puts
|
253
|
+
|
254
|
+
log_entries = [
|
255
|
+
{ service: 'user-service', level: 'INFO', msg: 'User authentication successful' },
|
256
|
+
{ service: 'payment-service', level: 'ERROR', msg: 'Credit card validation failed' },
|
257
|
+
{ service: 'critical-service', level: 'FATAL', msg: 'Database connection lost' },
|
258
|
+
{ service: 'user-service', level: 'DEBUG', msg: 'Cache miss for user profile' }
|
259
|
+
]
|
260
|
+
|
261
|
+
log_entries.each_with_index do |log, i|
|
262
|
+
message = LogMessage.new(
|
263
|
+
log_id: "LOG-#{Time.now.to_i}-#{i}",
|
264
|
+
level: log[:level],
|
265
|
+
service: log[:service],
|
266
|
+
message: log[:msg],
|
267
|
+
context: {
|
268
|
+
thread_id: "thread_#{i}",
|
269
|
+
request_id: "req_#{100 + i}"
|
270
|
+
}
|
271
|
+
)
|
272
|
+
message.from(log[:service])
|
273
|
+
message.publish
|
274
|
+
|
275
|
+
sleep 0.1
|
276
|
+
end
|
277
|
+
|
278
|
+
puts "✅ Published 4 log entries from different services"
|
279
|
+
puts
|
280
|
+
end
|
281
|
+
|
282
|
+
def demonstrate_metrics_collection
|
283
|
+
puts "📊 Demonstrating metrics collection..."
|
284
|
+
puts
|
285
|
+
|
286
|
+
metrics = [
|
287
|
+
{ agent: 'cpu-monitor', name: 'cpu.usage.percent', value: 78.5, tags: { host: 'web-01' } },
|
288
|
+
{ agent: 'memory-monitor', name: 'memory.used.bytes', value: 2147483648, tags: { host: 'web-01' } },
|
289
|
+
{ agent: 'disk-monitor', name: 'disk.free.percent', value: 45.2, tags: { mount: '/data' } },
|
290
|
+
{ agent: 'network-monitor', name: 'network.bytes.sent', value: 1048576, tags: { interface: 'eth0' } }
|
291
|
+
]
|
292
|
+
|
293
|
+
metrics.each_with_index do |metric, i|
|
294
|
+
message = MetricsMessage.new(
|
295
|
+
metric_id: "MET-#{Time.now.to_i}-#{i}",
|
296
|
+
metric_name: metric[:name],
|
297
|
+
value: metric[:value],
|
298
|
+
tags: metric[:tags]
|
299
|
+
)
|
300
|
+
message.from(metric[:agent])
|
301
|
+
message.publish
|
302
|
+
|
303
|
+
sleep 0.1
|
304
|
+
end
|
305
|
+
|
306
|
+
puts "✅ Published 4 metrics from different monitoring agents"
|
307
|
+
puts
|
308
|
+
end
|
309
|
+
|
310
|
+
def show_routing_patterns_summary
|
311
|
+
puts "📋 Active Routing Patterns Summary:"
|
312
|
+
puts "=" * 40
|
313
|
+
puts
|
314
|
+
|
315
|
+
puts "🎯 Service-to-Service Routing:"
|
316
|
+
puts " • api-gateway → user-service"
|
317
|
+
puts " • api-gateway → order-service"
|
318
|
+
puts " • api-gateway → payment-service"
|
319
|
+
puts
|
320
|
+
|
321
|
+
puts "🗄️ Database Query Routing:"
|
322
|
+
puts " • user-orm → database-service"
|
323
|
+
puts " • order-orm → database-service"
|
324
|
+
puts " • analytics-orm → database-service"
|
325
|
+
puts
|
326
|
+
|
327
|
+
puts "📋 Log Aggregation Routing:"
|
328
|
+
puts " • user-service → log-aggregator"
|
329
|
+
puts " • payment-service → log-aggregator"
|
330
|
+
puts " • critical-service → log-aggregator"
|
331
|
+
puts
|
332
|
+
|
333
|
+
puts "📊 Metrics Collection Routing:"
|
334
|
+
puts " • cpu-monitor → metrics-collector"
|
335
|
+
puts " • memory-monitor → metrics-collector"
|
336
|
+
puts " • disk-monitor → metrics-collector"
|
337
|
+
puts " • network-monitor → metrics-collector"
|
338
|
+
puts
|
339
|
+
end
|
340
|
+
|
341
|
+
#==============================================================================
|
342
|
+
# Main Demonstration
|
343
|
+
#==============================================================================
|
344
|
+
|
345
|
+
begin
|
346
|
+
puts "🔧 Checking Redis connection..."
|
347
|
+
unless transport.connected?
|
348
|
+
puts "❌ Redis not available. Please start Redis server:"
|
349
|
+
puts " brew services start redis # macOS"
|
350
|
+
puts " sudo service redis start # Linux"
|
351
|
+
exit 1
|
352
|
+
end
|
353
|
+
puts "✅ Connected to Redis"
|
354
|
+
puts
|
355
|
+
|
356
|
+
# Set up advanced routing patterns
|
357
|
+
setup_service_specific_routing(transport)
|
358
|
+
setup_log_level_filtering(transport)
|
359
|
+
setup_metrics_collection_routing(transport)
|
360
|
+
|
361
|
+
# Subscribe message classes
|
362
|
+
ApiRequestMessage.subscribe
|
363
|
+
DatabaseQueryMessage.subscribe
|
364
|
+
LogMessage.subscribe
|
365
|
+
MetricsMessage.subscribe
|
366
|
+
|
367
|
+
puts "⏳ Waiting for subscriptions to be established..."
|
368
|
+
sleep 1
|
369
|
+
|
370
|
+
# Demonstrate different routing scenarios
|
371
|
+
demonstrate_dynamic_routing
|
372
|
+
sleep 0.5
|
373
|
+
|
374
|
+
demonstrate_database_query_routing
|
375
|
+
sleep 0.5
|
376
|
+
|
377
|
+
demonstrate_log_aggregation_routing
|
378
|
+
sleep 0.5
|
379
|
+
|
380
|
+
demonstrate_metrics_collection
|
381
|
+
sleep 1
|
382
|
+
|
383
|
+
puts "⏳ Processing messages (waiting 3 seconds)..."
|
384
|
+
sleep 3
|
385
|
+
|
386
|
+
# Show summary
|
387
|
+
show_routing_patterns_summary
|
388
|
+
|
389
|
+
# Show active pattern subscriptions
|
390
|
+
puts "🔍 Active Pattern Subscriptions:"
|
391
|
+
pattern_subscriptions = transport.instance_variable_get(:@pattern_subscriptions)
|
392
|
+
if pattern_subscriptions && pattern_subscriptions.any?
|
393
|
+
pattern_subscriptions.each_with_index do |pattern, i|
|
394
|
+
puts " #{i + 1}. #{pattern}"
|
395
|
+
end
|
396
|
+
else
|
397
|
+
puts " No pattern subscriptions found"
|
398
|
+
end
|
399
|
+
puts
|
400
|
+
|
401
|
+
puts "🎉 Advanced Routing Demo completed!"
|
402
|
+
puts
|
403
|
+
puts "💡 Advanced Routing Benefits:"
|
404
|
+
puts " • Precise message targeting with multiple conditions"
|
405
|
+
puts " • Dynamic routing based on message content"
|
406
|
+
puts " • Service-specific pattern matching"
|
407
|
+
puts " • Complex microservices communication patterns"
|
408
|
+
puts " • Flexible subscription management"
|
409
|
+
|
410
|
+
rescue Interrupt
|
411
|
+
puts "\n👋 Demo interrupted by user"
|
412
|
+
rescue => e
|
413
|
+
puts "💥 Error: #{e.message}"
|
414
|
+
puts e.backtrace[0..3]
|
415
|
+
ensure
|
416
|
+
puts "\n🧹 Cleaning up..."
|
417
|
+
transport&.disconnect
|
418
|
+
puts "✅ Disconnected from Redis"
|
419
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="900" height="800" viewBox="0 0 900 800" xmlns="http://www.w3.org/2000/svg">
|
3
|
+
<defs>
|
4
|
+
<style>
|
5
|
+
.bg { fill: transparent; }
|
6
|
+
.producer { fill: #2a3a2a; stroke: #4aff4a; stroke-width: 2; rx: 8; }
|
7
|
+
.consumer { fill: #3a2a3a; stroke: #4a9eff; stroke-width: 2; rx: 8; }
|
8
|
+
.redis { fill: #3a1a1a; stroke: #ff4a4a; stroke-width: 3; rx: 12; }
|
9
|
+
.stream { fill: #1a2a3a; stroke: #ffaa4a; stroke-width: 2; rx: 6; }
|
10
|
+
.group { fill: #2a1a3a; stroke: #aa4aff; stroke-width: 2; rx: 6; }
|
11
|
+
.arrow { stroke: #ffaa4a; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
|
12
|
+
.ack-arrow { stroke: #4aff4a; stroke-width: 2; fill: none; marker-end: url(#ack-arrowhead); 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
|
+
.redis-text { fill: #ff4a4a; font-family: 'Arial', sans-serif; font-size: 14px; font-weight: bold; }
|
17
|
+
.stream-text { fill: #ffaa4a; font-family: 'Arial', sans-serif; font-size: 10px; }
|
18
|
+
.group-text { fill: #aa4aff; font-family: 'Arial', sans-serif; font-size: 10px; }
|
19
|
+
</style>
|
20
|
+
<marker id="arrowhead" markerWidth="8" markerHeight="6"
|
21
|
+
refX="8" refY="3" orient="auto">
|
22
|
+
<polygon points="0 0, 8 3, 0 6" fill="#ffaa4a" />
|
23
|
+
</marker>
|
24
|
+
<marker id="ack-arrowhead" markerWidth="8" markerHeight="6"
|
25
|
+
refX="8" refY="3" orient="auto">
|
26
|
+
<polygon points="0 0, 8 3, 0 6" fill="#4aff4a" />
|
27
|
+
</marker>
|
28
|
+
</defs>
|
29
|
+
|
30
|
+
<!-- Background -->
|
31
|
+
<rect class="bg" width="900" height="800"/>
|
32
|
+
|
33
|
+
<!-- Title -->
|
34
|
+
<text x="450" y="25" text-anchor="middle" class="title">SmartMessage Redis Queue Transport Architecture</text>
|
35
|
+
<text x="450" y="45" text-anchor="middle" class="subtitle">Reliable Message Queuing with Consumer Groups and Acknowledgments</text>
|
36
|
+
|
37
|
+
<!-- Redis Server (Central Hub) -->
|
38
|
+
<rect x="300" y="320" width="300" height="180" class="redis"/>
|
39
|
+
<text x="450" y="345" text-anchor="middle" class="redis-text">Redis Server (v5.0+)</text>
|
40
|
+
<text x="450" y="365" text-anchor="middle" class="text">Streams + Consumer Groups</text>
|
41
|
+
|
42
|
+
<!-- Redis Streams -->
|
43
|
+
<rect x="320" y="380" width="260" height="40" class="stream"/>
|
44
|
+
<text x="450" y="395" text-anchor="middle" class="stream-text">Stream: OrderMessage</text>
|
45
|
+
<text x="450" y="410" text-anchor="middle" class="stream-text">Messages: [msg1, msg2, msg3, msg4, ...]</text>
|
46
|
+
|
47
|
+
<!-- Consumer Groups -->
|
48
|
+
<rect x="320" y="430" width="120" height="60" class="group"/>
|
49
|
+
<text x="380" y="450" text-anchor="middle" class="group-text">Consumer Group:</text>
|
50
|
+
<text x="380" y="465" text-anchor="middle" class="group-text">order_processors</text>
|
51
|
+
<text x="380" y="480" text-anchor="middle" class="group-text">worker-1, worker-2</text>
|
52
|
+
|
53
|
+
<rect x="460" y="430" width="120" height="60" class="group"/>
|
54
|
+
<text x="520" y="450" text-anchor="middle" class="group-text">Consumer Group:</text>
|
55
|
+
<text x="520" y="465" text-anchor="middle" class="group-text">notification_workers</text>
|
56
|
+
<text x="520" y="480" text-anchor="middle" class="group-text">worker-3, worker-4</text>
|
57
|
+
|
58
|
+
<!-- Producers -->
|
59
|
+
<rect x="50" y="150" width="150" height="80" class="producer"/>
|
60
|
+
<text x="125" y="175" text-anchor="middle" class="title">Producer 1</text>
|
61
|
+
<text x="125" y="195" text-anchor="middle" class="text">Order API</text>
|
62
|
+
<text x="125" y="215" text-anchor="middle" class="subtitle">Publishes OrderMessage</text>
|
63
|
+
|
64
|
+
<rect x="50" y="250" width="150" height="80" class="producer"/>
|
65
|
+
<text x="125" y="275" text-anchor="middle" class="title">Producer 2</text>
|
66
|
+
<text x="125" y="295" text-anchor="middle" class="text">User Service</text>
|
67
|
+
<text x="125" y="315" text-anchor="middle" class="subtitle">Publishes UserMessage</text>
|
68
|
+
|
69
|
+
<rect x="50" y="550" width="150" height="80" class="producer"/>
|
70
|
+
<text x="125" y="575" text-anchor="middle" class="title">Producer 3</text>
|
71
|
+
<text x="125" y="595" text-anchor="middle" class="text">Alert System</text>
|
72
|
+
<text x="125" y="615" text-anchor="middle" class="subtitle">Publishes AlertMessage</text>
|
73
|
+
|
74
|
+
<!-- Consumers -->
|
75
|
+
<rect x="700" y="150" width="150" height="80" class="consumer"/>
|
76
|
+
<text x="775" y="175" text-anchor="middle" class="title">Worker 1</text>
|
77
|
+
<text x="775" y="195" text-anchor="middle" class="text">Order Processor</text>
|
78
|
+
<text x="775" y="215" text-anchor="middle" class="subtitle">Group: order_processors</text>
|
79
|
+
|
80
|
+
<rect x="700" y="250" width="150" height="80" class="consumer"/>
|
81
|
+
<text x="775" y="275" text-anchor="middle" class="title">Worker 2</text>
|
82
|
+
<text x="775" y="295" text-anchor="middle" class="text">Order Processor</text>
|
83
|
+
<text x="775" y="315" text-anchor="middle" class="subtitle">Group: order_processors</text>
|
84
|
+
|
85
|
+
<rect x="700" y="400" width="150" height="80" class="consumer"/>
|
86
|
+
<text x="775" y="425" text-anchor="middle" class="title">Worker 3</text>
|
87
|
+
<text x="775" y="445" text-anchor="middle" class="text">Email Service</text>
|
88
|
+
<text x="775" y="465" text-anchor="middle" class="subtitle">Group: notification_workers</text>
|
89
|
+
|
90
|
+
<rect x="700" y="550" width="150" height="80" class="consumer"/>
|
91
|
+
<text x="775" y="575" text-anchor="middle" class="title">Worker 4</text>
|
92
|
+
<text x="775" y="595" text-anchor="middle" class="text">SMS Service</text>
|
93
|
+
<text x="775" y="615" text-anchor="middle" class="subtitle">Group: notification_workers</text>
|
94
|
+
|
95
|
+
<!-- Message Flow Arrows -->
|
96
|
+
<!-- Producers to Redis -->
|
97
|
+
<path d="M 200 190 L 300 380" class="arrow"/>
|
98
|
+
<path d="M 200 290 L 300 400" class="arrow"/>
|
99
|
+
<path d="M 200 590 L 300 420" class="arrow"/>
|
100
|
+
|
101
|
+
<!-- Redis to Consumers -->
|
102
|
+
<path d="M 600 390 L 700 190" class="arrow"/>
|
103
|
+
<path d="M 600 400 L 700 290" class="arrow"/>
|
104
|
+
<path d="M 600 450 L 700 440" class="arrow"/>
|
105
|
+
<path d="M 600 460 L 700 590" class="arrow"/>
|
106
|
+
|
107
|
+
<!-- Acknowledgment arrows (dashed green) -->
|
108
|
+
<path d="M 700 210 L 600 410" class="ack-arrow"/>
|
109
|
+
<path d="M 700 310 L 600 410" class="ack-arrow"/>
|
110
|
+
<path d="M 700 460 L 600 470" class="ack-arrow"/>
|
111
|
+
<path d="M 700 610 L 600 470" class="ack-arrow"/>
|
112
|
+
|
113
|
+
<!-- Message Flow Process -->
|
114
|
+
<rect x="50" y="680" width="800" height="110" class="redis"/>
|
115
|
+
<text x="70" y="705" class="title">Message Flow Process</text>
|
116
|
+
|
117
|
+
<circle cx="90" cy="730" r="12" fill="#4aff4a"/>
|
118
|
+
<text x="90" y="735" text-anchor="middle" class="text">1</text>
|
119
|
+
<text x="110" y="735" class="text">Producer publishes message to Redis Stream</text>
|
120
|
+
|
121
|
+
<circle cx="450" cy="730" r="12" fill="#ffaa4a"/>
|
122
|
+
<text x="450" y="735" text-anchor="middle" class="text">2</text>
|
123
|
+
<text x="470" y="735" class="text">Message added to stream with unique ID</text>
|
124
|
+
|
125
|
+
<circle cx="90" cy="755" r="12" fill="#4a9eff"/>
|
126
|
+
<text x="90" y="760" text-anchor="middle" class="text">3</text>
|
127
|
+
<text x="110" y="760" class="text">Consumer group distributes message to available worker</text>
|
128
|
+
|
129
|
+
<circle cx="450" cy="755" r="12" fill="#aa4aff"/>
|
130
|
+
<text x="450" y="760" text-anchor="middle" class="text">4</text>
|
131
|
+
<text x="470" y="760" class="text">Worker processes message and sends acknowledgment</text>
|
132
|
+
|
133
|
+
<circle cx="90" cy="780" r="12" fill="#ff4a4a"/>
|
134
|
+
<text x="90" y="785" text-anchor="middle" class="text">5</text>
|
135
|
+
<text x="110" y="785" class="text">If no ACK received, message redistributed to another worker</text>
|
136
|
+
|
137
|
+
<!-- Key Features -->
|
138
|
+
<text x="50" y="80" class="title">Key Features:</text>
|
139
|
+
<text x="70" y="100" class="text">✓ Guaranteed Delivery: Messages persist until acknowledged</text>
|
140
|
+
<text x="70" y="115" class="text">✓ Load Balancing: Consumer groups distribute work automatically</text>
|
141
|
+
|
142
|
+
<text x="450" y="100" class="text">✓ Fault Tolerance: Failed workers don't lose messages</text>
|
143
|
+
<text x="450" y="115" class="text">✓ At-Least-Once: Messages redelivered on failure</text>
|
144
|
+
|
145
|
+
<text x="650" y="80" class="title">Use Cases:</text>
|
146
|
+
<text x="670" y="100" class="text">• Background job processing</text>
|
147
|
+
<text x="670" y="115" class="text">• Order processing pipelines</text>
|
148
|
+
</svg>
|
data/ideas/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# SmartMessage Ideas and Design Discussions
|
2
|
+
|
3
|
+
This directory contains design discussions and architectural ideas for extending the SmartMessage framework. Each document explores a different aspect of potential enhancements to the system.
|
4
|
+
|
5
|
+
## database_transport.md
|
6
|
+
|
7
|
+
Explores implementing a database-backed transport layer for SmartMessage, enabling persistent message queuing and reliable delivery without requiring external message brokers like RabbitMQ or Kafka. This approach would store messages directly in a PostgreSQL or MySQL database, providing built-in persistence, transactional guarantees, and the ability to query message history.
|
8
|
+
|
9
|
+
The design includes database schema definitions, message lifecycle management (pending, processing, completed, failed states), retry mechanisms with exponential backoff, and dead letter queue functionality. This transport would be particularly useful for applications that already have a database but don't want the operational complexity of managing a separate message broker, or for scenarios requiring long-term message retention and complex querying capabilities.
|
10
|
+
|
11
|
+
## improvement.md
|
12
|
+
|
13
|
+
Contains a comprehensive list of potential improvements and enhancements to the SmartMessage framework, covering areas from core functionality to developer experience. The ideas range from technical enhancements like performance optimizations and new transport implementations to architectural improvements such as better plugin systems and schema management.
|
14
|
+
|
15
|
+
Key improvement areas include adding support for additional transports (Redis, AWS SQS, Google Pub/Sub), implementing message compression and encryption, enhancing the validation framework, improving error handling and retry logic, and adding comprehensive metrics and monitoring capabilities. The document also explores developer experience improvements like better debugging tools, enhanced documentation, and a potential web UI for message inspection.
|
16
|
+
|
17
|
+
## message_discovery.md
|
18
|
+
|
19
|
+
Focuses on the service discovery and dynamic class creation capabilities that would allow SmartMessage-based services to automatically discover and use message types from other services without manual integration. This system would enable services to query a central registry to find available message schemas and dynamically create the corresponding Ruby classes at runtime.
|
20
|
+
|
21
|
+
The discovery mechanism includes APIs for browsing available message types by service, environment, or tags, dynamic class generation from stored schemas without requiring Ruby source files, and automatic synchronization when schemas are updated. This enables true microservice architectures where services can integrate with new message types without code changes or deployments, supporting patterns like partner integrations, multi-tenant systems, and runtime service composition.
|
22
|
+
|
23
|
+
## message_schema.md
|
24
|
+
|
25
|
+
Describes a comprehensive schema registry system that transforms SmartMessage from a messaging framework into a schema management platform. The core innovation is bidirectional conversion between SmartMessage Ruby classes and JSON Schema, enabling message definitions to be stored as data rather than code.
|
26
|
+
|
27
|
+
The system includes automatic schema registration when classes are defined, version tracking and evolution management, and most importantly, the ability to serialize a Ruby class definition to JSON Schema and reconstruct it later using `to_json_schema` and `from_json_schema` methods. This enables powerful capabilities like storing schemas in databases, sharing schemas across different programming languages (with examples for Rust, Python, TypeScript, Go, and Java), runtime schema updates without deployment, and schema governance with approval workflows. The JSON Schema approach provides cross-language interoperability while maintaining safety (no code execution) and human readability, fundamentally changing how distributed systems manage message contracts.
|
28
|
+
|
29
|
+
## meshage.md
|
30
|
+
|
31
|
+
Explores implementing a true mesh network transport for SmartMessage that enables completely decentralized messaging with location-agnostic publishing. Unlike direct peer-to-peer systems, mesh networks allow publishers to send messages to service names without knowing which physical nodes host those services - the mesh automatically routes messages through intermediate nodes until they reach their destination or expire.
|
32
|
+
|
33
|
+
The design emphasizes the key mesh network principles of complete decentralization, multi-hop message routing, and self-terminating messages with TTL. Services register themselves with the mesh, and the network maintains a distributed service directory that enables automatic route discovery. Messages can travel through multiple intermediate nodes (A → C → F → K) to reach their destination, with the mesh providing fault tolerance through alternate routing paths. The document incorporates insights from existing P2P libraries (journeta, p2p2) for proven patterns in NAT traversal, connection management, and network coordination. Multi-layer deduplication ensures message storms are prevented at subscriber, node, and network levels, while network control messages handle presence, health monitoring, and graceful shutdown protocols.
|
34
|
+
|
35
|
+
## agents.md
|
36
|
+
|
37
|
+
Comprehensive exploration of AI agents using SmartMessage for intelligent communication patterns. The document examines how AI agents represent the next evolution in distributed systems - intelligent entities that can make contextual decisions, adapt to scenarios, and communicate using natural language understanding combined with structured messaging.
|
38
|
+
|
39
|
+
The analysis covers three complementary architecture patterns: Agent99 for request/response service coordination, SmartMessage AI for context-aware dynamic messaging, and hybrid approaches that combine both. Key innovations include contextual message selection where AI chooses appropriate message types based on scenarios, intelligent property generation using LLM understanding of validation constraints, and self-healing validation with automatic retry logic.
|
40
|
+
|
41
|
+
The document includes a crucial analysis of Model Context Protocol (MCP) integration, demonstrating how MCP's resource sharing capabilities complement rather than compete with SmartMessage+Agent99. The integration creates a three-layer intelligence stack: Context Layer (MCP) for rich data access, Intelligence Layer (AI + SmartMessage) for smart decision making, and Coordination Layer (Agent99) for multi-agent orchestration. Real-world applications span smart city management, autonomous supply chains, and healthcare coordination systems, showing how these technologies enable truly intelligent distributed systems that understand context, communicate naturally, and coordinate seamlessly.
|