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