smart_message 0.0.12 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -1
- data/Gemfile.lock +5 -5
- data/docs/core-concepts/architecture.md +5 -10
- data/docs/getting-started/examples.md +0 -12
- data/docs/getting-started/quick-start.md +4 -9
- data/docs/index.md +4 -4
- data/docs/reference/serializers.md +160 -488
- data/docs/reference/transports.md +1 -125
- data/docs/transports/redis-transport-comparison.md +215 -350
- data/docs/transports/redis-transport.md +3 -22
- data/examples/README.md +6 -9
- data/examples/city_scenario/README.md +1 -1
- data/examples/city_scenario/messages/emergency_911_message.rb +0 -1
- data/examples/city_scenario/messages/emergency_resolved_message.rb +0 -1
- data/examples/city_scenario/messages/fire_dispatch_message.rb +0 -1
- data/examples/city_scenario/messages/fire_emergency_message.rb +0 -1
- data/examples/city_scenario/messages/health_check_message.rb +0 -1
- data/examples/city_scenario/messages/health_status_message.rb +0 -1
- data/examples/city_scenario/messages/police_dispatch_message.rb +0 -1
- data/examples/city_scenario/messages/silent_alarm_message.rb +0 -1
- data/examples/memory/01_message_deduplication_demo.rb +0 -2
- data/examples/memory/02_dead_letter_queue_demo.rb +0 -3
- data/examples/memory/03_point_to_point_orders.rb +0 -2
- data/examples/memory/04_publish_subscribe_events.rb +0 -1
- data/examples/memory/05_many_to_many_chat.rb +0 -3
- data/examples/memory/07_proc_handlers_demo.rb +0 -1
- data/examples/memory/08_custom_logger_demo.rb +0 -4
- data/examples/memory/09_error_handling_demo.rb +0 -3
- data/examples/memory/10_entity_addressing_basic.rb +0 -6
- data/examples/memory/11_entity_addressing_with_filtering.rb +0 -4
- data/examples/memory/12_regex_filtering_microservices.rb +0 -1
- data/examples/memory/13_header_block_configuration.rb +0 -5
- data/examples/memory/14_global_configuration_demo.rb +0 -2
- data/examples/memory/15_logger_demo.rb +0 -1
- data/examples/memory/README.md +3 -3
- data/examples/redis/01_smart_home_iot_demo.rb +0 -4
- data/examples/redis/README.md +0 -2
- data/lib/smart_message/base.rb +19 -10
- data/lib/smart_message/configuration.rb +2 -23
- data/lib/smart_message/dead_letter_queue.rb +1 -1
- data/lib/smart_message/messaging.rb +3 -62
- data/lib/smart_message/plugins.rb +1 -42
- data/lib/smart_message/transport/base.rb +42 -8
- data/lib/smart_message/transport/memory_transport.rb +23 -4
- data/lib/smart_message/transport/redis_transport.rb +11 -0
- data/lib/smart_message/transport/registry.rb +0 -1
- data/lib/smart_message/transport/stdout_transport.rb +28 -10
- data/lib/smart_message/transport.rb +0 -1
- data/lib/smart_message/version.rb +1 -1
- metadata +2 -28
- data/docs/guides/redis-queue-getting-started.md +0 -697
- data/docs/guides/redis-queue-patterns.md +0 -889
- data/docs/guides/redis-queue-production.md +0 -1091
- data/docs/transports/redis-enhanced-transport.md +0 -524
- data/docs/transports/redis-queue-transport.md +0 -1304
- data/examples/redis_enhanced/README.md +0 -319
- data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +0 -233
- data/examples/redis_enhanced/enhanced_02_fluent_api.rb +0 -331
- data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +0 -281
- data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +0 -419
- data/examples/redis_queue/01_basic_messaging.rb +0 -221
- data/examples/redis_queue/01_comprehensive_examples.rb +0 -508
- data/examples/redis_queue/02_pattern_routing.rb +0 -405
- data/examples/redis_queue/03_fluent_api.rb +0 -422
- data/examples/redis_queue/04_load_balancing.rb +0 -486
- data/examples/redis_queue/05_microservices.rb +0 -735
- data/examples/redis_queue/06_emergency_alerts.rb +0 -777
- data/examples/redis_queue/07_queue_management.rb +0 -587
- data/examples/redis_queue/README.md +0 -366
- data/examples/redis_queue/enhanced_01_basic_patterns.rb +0 -233
- data/examples/redis_queue/enhanced_02_fluent_api.rb +0 -331
- data/examples/redis_queue/enhanced_03_dual_publishing.rb +0 -281
- data/examples/redis_queue/enhanced_04_advanced_routing.rb +0 -419
- data/examples/redis_queue/redis_queue_architecture.svg +0 -148
- data/lib/smart_message/transport/redis_enhanced_transport.rb +0 -399
- data/lib/smart_message/transport/redis_queue_transport.rb +0 -555
@@ -1,419 +0,0 @@
|
|
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
|
@@ -1,148 +0,0 @@
|
|
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>
|