smart_message 0.0.13 → 0.0.16
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/.gitignore +1 -0
- data/CHANGELOG.md +120 -0
- data/Gemfile.lock +3 -3
- data/README.md +71 -25
- data/docs/index.md +2 -0
- data/docs/reference/transports.md +46 -21
- data/docs/transports/memory-transport.md +2 -1
- data/docs/transports/multi-transport.md +484 -0
- data/examples/file/00_run_all_file_demos.rb +260 -0
- data/examples/file/01_basic_file_transport_demo.rb +237 -0
- data/examples/file/02_fifo_transport_demo.rb +289 -0
- data/examples/file/03_file_watching_demo.rb +332 -0
- data/examples/file/04_multi_transport_file_demo.rb +432 -0
- data/examples/file/README.md +257 -0
- data/examples/memory/00_run_all_demos.rb +317 -0
- data/examples/memory/01_message_deduplication_demo.rb +18 -30
- data/examples/memory/02_dead_letter_queue_demo.rb +9 -9
- data/examples/memory/03_point_to_point_orders.rb +3 -3
- data/examples/memory/04_publish_subscribe_events.rb +15 -15
- data/examples/memory/05_many_to_many_chat.rb +19 -19
- data/examples/memory/06_stdout_publish_only.rb +145 -0
- data/examples/memory/07_proc_handlers_demo.rb +13 -13
- data/examples/memory/08_custom_logger_demo.rb +136 -136
- data/examples/memory/09_error_handling_demo.rb +7 -7
- data/examples/memory/10_entity_addressing_basic.rb +25 -25
- data/examples/memory/11_entity_addressing_with_filtering.rb +32 -32
- data/examples/memory/12_regex_filtering_microservices.rb +10 -10
- data/examples/memory/14_global_configuration_demo.rb +12 -12
- data/examples/memory/README.md +34 -17
- data/examples/memory/log/demo_app.log.1 +100 -0
- data/examples/memory/log/demo_app.log.2 +100 -0
- data/examples/multi_transport_example.rb +114 -0
- data/examples/redis/01_smart_home_iot_demo.rb +20 -20
- data/examples/utilities/box_it.rb +12 -0
- data/examples/utilities/doing.rb +19 -0
- data/examples/utilities/temp.md +28 -0
- data/lib/smart_message/base.rb +5 -7
- data/lib/smart_message/errors.rb +3 -0
- data/lib/smart_message/header.rb +1 -1
- data/lib/smart_message/logger/default.rb +1 -1
- data/lib/smart_message/messaging.rb +36 -6
- data/lib/smart_message/plugins.rb +46 -4
- data/lib/smart_message/serializer/base.rb +1 -1
- data/lib/smart_message/serializer.rb +3 -2
- data/lib/smart_message/subscription.rb +18 -20
- data/lib/smart_message/transport/async_publish_queue.rb +284 -0
- data/lib/smart_message/transport/fifo_operations.rb +264 -0
- data/lib/smart_message/transport/file_operations.rb +200 -0
- data/lib/smart_message/transport/file_transport.rb +149 -0
- data/lib/smart_message/transport/file_watching.rb +72 -0
- data/lib/smart_message/transport/partitioned_files.rb +46 -0
- data/lib/smart_message/transport/stdout_transport.rb +50 -36
- data/lib/smart_message/transport/stdout_transport.rb.backup +88 -0
- data/lib/smart_message/version.rb +1 -1
- metadata +24 -10
- data/ideas/README.md +0 -41
- data/ideas/agents.md +0 -1001
- data/ideas/database_transport.md +0 -980
- data/ideas/improvement.md +0 -359
- data/ideas/meshage.md +0 -1788
- data/ideas/message_discovery.md +0 -178
- data/ideas/message_schema.md +0 -1381
- data/lib/smart_message/wrapper.rb.bak +0 -132
- /data/examples/memory/{06_pretty_print_demo.rb → 16_pretty_print_demo.rb} +0 -0
@@ -0,0 +1,317 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# examples/memory/00_run_all_demos.rb
|
3
|
+
#
|
4
|
+
# Master Demo Runner - Executes All SmartMessage Memory Transport Examples
|
5
|
+
#
|
6
|
+
# This script runs all the demo programs in the examples/memory directory
|
7
|
+
# in sequence, with clear banners to show which demo is currently running.
|
8
|
+
|
9
|
+
require 'fileutils'
|
10
|
+
require 'pathname'
|
11
|
+
|
12
|
+
class SmartMessageDemoRunner
|
13
|
+
DEMO_PROGRAMS = [
|
14
|
+
{
|
15
|
+
file: "01_message_deduplication_demo.rb",
|
16
|
+
title: "Message Deduplication with DDQ",
|
17
|
+
description: "Demonstrates message deduplication patterns and duplicate message prevention",
|
18
|
+
duration: "~10 seconds"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
file: "02_dead_letter_queue_demo.rb",
|
22
|
+
title: "Dead Letter Queue & Error Handling",
|
23
|
+
description: "Shows DLQ pattern implementation with circuit breakers and error recovery",
|
24
|
+
duration: "~15 seconds"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
file: "03_point_to_point_orders.rb",
|
28
|
+
title: "Point-to-Point Order Processing",
|
29
|
+
description: "Order processing system with 1:1 messaging between OrderService and PaymentService",
|
30
|
+
duration: "~8 seconds"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
file: "04_publish_subscribe_events.rb",
|
34
|
+
title: "Publish-Subscribe Event Broadcasting",
|
35
|
+
description: "Event-driven architecture with multiple subscribers (Email, SMS, Audit)",
|
36
|
+
duration: "~10 seconds"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
file: "05_many_to_many_chat.rb",
|
40
|
+
title: "Many-to-Many Chat System",
|
41
|
+
description: "Interactive chat system with rooms, bots, and human agents",
|
42
|
+
duration: "~12 seconds"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
file: "06_stdout_publish_only.rb",
|
46
|
+
title: "STDOUT Transport (Publish-Only)",
|
47
|
+
description: "Demonstrates STDOUT transport for logging and external tool integration",
|
48
|
+
duration: "~5 seconds"
|
49
|
+
},
|
50
|
+
{
|
51
|
+
file: "07_proc_handlers_demo.rb",
|
52
|
+
title: "Proc-Based Message Handlers",
|
53
|
+
description: "Flexible message handlers using blocks, procs, lambdas, and methods",
|
54
|
+
duration: "~8 seconds"
|
55
|
+
},
|
56
|
+
{
|
57
|
+
file: "08_custom_logger_demo.rb",
|
58
|
+
title: "Custom Logging Implementations",
|
59
|
+
description: "Advanced logging with multiple loggers and custom formatting",
|
60
|
+
duration: "~12 seconds"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
file: "09_error_handling_demo.rb",
|
64
|
+
title: "Comprehensive Error Handling",
|
65
|
+
description: "Error handling strategies, validation failures, and graceful degradation",
|
66
|
+
duration: "~10 seconds"
|
67
|
+
},
|
68
|
+
{
|
69
|
+
file: "10_entity_addressing_basic.rb",
|
70
|
+
title: "Entity Addressing Basics",
|
71
|
+
description: "Message routing by entity addresses with FROM/TO/REPLY_TO patterns",
|
72
|
+
duration: "~8 seconds"
|
73
|
+
},
|
74
|
+
{
|
75
|
+
file: "11_entity_addressing_with_filtering.rb",
|
76
|
+
title: "Advanced Entity Addressing & Filtering",
|
77
|
+
description: "Complex filtering patterns with regex-based address matching",
|
78
|
+
duration: "~10 seconds"
|
79
|
+
},
|
80
|
+
{
|
81
|
+
file: "12_regex_filtering_microservices.rb",
|
82
|
+
title: "Microservices with Regex Filtering",
|
83
|
+
description: "Service-to-service communication with environment-based filtering",
|
84
|
+
duration: "~8 seconds"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
file: "13_header_block_configuration.rb",
|
88
|
+
title: "Header Block Configuration",
|
89
|
+
description: "Dynamic header configuration with block-based modification",
|
90
|
+
duration: "~6 seconds"
|
91
|
+
},
|
92
|
+
{
|
93
|
+
file: "14_global_configuration_demo.rb",
|
94
|
+
title: "Global Configuration Management",
|
95
|
+
description: "Global transport settings and configuration inheritance",
|
96
|
+
duration: "~8 seconds"
|
97
|
+
},
|
98
|
+
{
|
99
|
+
file: "15_logger_demo.rb",
|
100
|
+
title: "Advanced Logger Configuration",
|
101
|
+
description: "Logger configuration, log levels, and SmartMessage lifecycle integration",
|
102
|
+
duration: "~10 seconds"
|
103
|
+
},
|
104
|
+
{
|
105
|
+
file: "16_pretty_print_demo.rb",
|
106
|
+
title: "Message Pretty-Printing",
|
107
|
+
description: "Message inspection and debugging with pretty-print formatting",
|
108
|
+
duration: "~5 seconds"
|
109
|
+
}
|
110
|
+
].freeze
|
111
|
+
|
112
|
+
def initialize
|
113
|
+
@base_dir = File.dirname(__FILE__)
|
114
|
+
@total_demos = DEMO_PROGRAMS.length
|
115
|
+
@start_time = Time.now
|
116
|
+
end
|
117
|
+
|
118
|
+
def run_all
|
119
|
+
print_main_banner
|
120
|
+
print_overview
|
121
|
+
|
122
|
+
DEMO_PROGRAMS.each_with_index do |demo, index|
|
123
|
+
run_demo(demo, index + 1)
|
124
|
+
end
|
125
|
+
|
126
|
+
print_completion_summary
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
# Helper method to calculate visual width of string accounting for emoji
|
132
|
+
def visual_width(str)
|
133
|
+
# Remove ANSI escape sequences if any
|
134
|
+
clean_str = str.gsub(/\e\[[0-9;]*m/, '')
|
135
|
+
|
136
|
+
# Count emoji and other wide characters
|
137
|
+
emoji_count = clean_str.scan(/[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/).length
|
138
|
+
|
139
|
+
# Each emoji takes up 2 visual columns but counts as 1 character
|
140
|
+
# So we add the emoji_count to get the actual visual width
|
141
|
+
clean_str.length + emoji_count
|
142
|
+
end
|
143
|
+
|
144
|
+
# Helper method to pad string to exact visual width
|
145
|
+
def pad_to_width(str, target_width)
|
146
|
+
current_width = visual_width(str)
|
147
|
+
if current_width <= target_width
|
148
|
+
str + (" " * (target_width - current_width))
|
149
|
+
else
|
150
|
+
# Truncate if too long, being careful about emoji
|
151
|
+
str[0...(target_width - current_width)]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def print_main_banner
|
156
|
+
puts "\n"
|
157
|
+
puts "█" * 100
|
158
|
+
puts "█" + " " * 98 + "█"
|
159
|
+
puts "█" + pad_to_width(" 🚀 SMARTMESSAGE COMPREHENSIVE DEMO SUITE 🚀 ", 98) + "█"
|
160
|
+
puts "█" + " " * 98 + "█"
|
161
|
+
puts "█" + pad_to_width(" Running all #{@total_demos} demo programs to showcase SmartMessage capabilities ", 98) + "█"
|
162
|
+
puts "█" + " " * 98 + "█"
|
163
|
+
puts "█" * 100
|
164
|
+
puts "\n"
|
165
|
+
end
|
166
|
+
|
167
|
+
def print_overview
|
168
|
+
puts "📋 DEMO OVERVIEW:"
|
169
|
+
puts "=" * 80
|
170
|
+
|
171
|
+
DEMO_PROGRAMS.each_with_index do |demo, index|
|
172
|
+
printf " %2d. %-35s %s\n",
|
173
|
+
index + 1,
|
174
|
+
demo[:title],
|
175
|
+
"(#{demo[:duration]})"
|
176
|
+
end
|
177
|
+
|
178
|
+
total_time = DEMO_PROGRAMS.sum { |demo|
|
179
|
+
demo[:duration].scan(/\d+/).first.to_i
|
180
|
+
}
|
181
|
+
|
182
|
+
puts "=" * 80
|
183
|
+
puts "📊 Total estimated time: ~#{total_time} seconds (~#{(total_time/60.0).round(1)} minutes)"
|
184
|
+
puts "🎯 Each demo runs independently with clear separation"
|
185
|
+
puts "⏸️ Press Ctrl+C at any time to stop the demo suite"
|
186
|
+
puts "\n"
|
187
|
+
end
|
188
|
+
|
189
|
+
def run_demo(demo, demo_number)
|
190
|
+
file_path = File.join(@base_dir, demo[:file])
|
191
|
+
|
192
|
+
unless File.exist?(file_path)
|
193
|
+
print_error_banner(demo_number, demo[:title], "File not found: #{demo[:file]}")
|
194
|
+
return
|
195
|
+
end
|
196
|
+
|
197
|
+
print_demo_banner(demo_number, demo)
|
198
|
+
|
199
|
+
start_time = Time.now
|
200
|
+
begin
|
201
|
+
# Execute the demo program
|
202
|
+
success = system("cd #{@base_dir} && ruby #{demo[:file]}")
|
203
|
+
end_time = Time.now
|
204
|
+
|
205
|
+
if success
|
206
|
+
print_demo_completion(demo_number, demo[:title], end_time - start_time)
|
207
|
+
else
|
208
|
+
print_demo_error(demo_number, demo[:title], "Demo exited with error code")
|
209
|
+
end
|
210
|
+
|
211
|
+
rescue Interrupt
|
212
|
+
puts "\n"
|
213
|
+
puts "🛑 DEMO SUITE INTERRUPTED BY USER"
|
214
|
+
puts " Completed #{demo_number - 1} of #{@total_demos} demos"
|
215
|
+
exit(0)
|
216
|
+
rescue => e
|
217
|
+
print_demo_error(demo_number, demo[:title], e.message)
|
218
|
+
end
|
219
|
+
|
220
|
+
print_demo_separator
|
221
|
+
end
|
222
|
+
|
223
|
+
def print_demo_banner(demo_number, demo)
|
224
|
+
puts "┌" + "─" * 98 + "┐"
|
225
|
+
puts "│" + " " * 98 + "│"
|
226
|
+
puts "│" + pad_to_width("🔥 DEMO #{demo_number.to_s.rjust(2, '0')}/#{@total_demos.to_s.rjust(2, '0')}: #{demo[:title]}", 98) + "│"
|
227
|
+
puts "│" + " " * 98 + "│"
|
228
|
+
puts "│" + pad_to_width("📝 #{demo[:description]}", 98) + "│"
|
229
|
+
puts "│" + pad_to_width("⏱️ Expected duration: #{demo[:duration]}", 98) + "│"
|
230
|
+
puts "│" + pad_to_width("📁 File: #{demo[:file]}", 98) + "│"
|
231
|
+
puts "│" + " " * 98 + "│"
|
232
|
+
puts "└" + "─" * 98 + "┘"
|
233
|
+
puts "\n"
|
234
|
+
end
|
235
|
+
|
236
|
+
def print_demo_completion(demo_number, title, actual_time)
|
237
|
+
puts "\n"
|
238
|
+
puts "✅ DEMO #{demo_number.to_s.rjust(2, '0')} COMPLETED: #{title}"
|
239
|
+
puts " ⏱️ Actual execution time: #{actual_time.round(2)} seconds"
|
240
|
+
puts "\n"
|
241
|
+
end
|
242
|
+
|
243
|
+
def print_demo_error(demo_number, title, error_message)
|
244
|
+
puts "\n"
|
245
|
+
puts "❌ DEMO #{demo_number.to_s.rjust(2, '0')} FAILED: #{title}"
|
246
|
+
puts " 🚨 Error: #{error_message}"
|
247
|
+
puts " ⏭️ Continuing with next demo..."
|
248
|
+
puts "\n"
|
249
|
+
end
|
250
|
+
|
251
|
+
def print_error_banner(demo_number, title, error_message)
|
252
|
+
puts "┌" + "─" * 98 + "┐"
|
253
|
+
puts "│" + pad_to_width("❌ DEMO #{demo_number.to_s.rjust(2, '0')}/#{@total_demos.to_s.rjust(2, '0')} ERROR: #{title}", 98) + "│"
|
254
|
+
puts "│" + " " * 98 + "│"
|
255
|
+
puts "│" + pad_to_width("🚨 #{error_message}", 98) + "│"
|
256
|
+
puts "│" + " " * 98 + "│"
|
257
|
+
puts "└" + "─" * 98 + "┘"
|
258
|
+
puts "\n"
|
259
|
+
end
|
260
|
+
|
261
|
+
def print_demo_separator
|
262
|
+
puts "═" * 100
|
263
|
+
puts "\n"
|
264
|
+
sleep(1) # Brief pause between demos for readability
|
265
|
+
end
|
266
|
+
|
267
|
+
def print_completion_summary
|
268
|
+
total_time = Time.now - @start_time
|
269
|
+
|
270
|
+
puts "\n"
|
271
|
+
puts "🏁" * 50
|
272
|
+
puts "🏁" + " " * 96 + "🏁"
|
273
|
+
puts "🏁" + pad_to_width(" 🎉 ALL DEMOS COMPLETED SUCCESSFULLY! 🎉 ", 96) + "🏁"
|
274
|
+
puts "🏁" + " " * 96 + "🏁"
|
275
|
+
puts "🏁" + pad_to_width(" Total execution time: #{total_time.round(2)} seconds (#{(total_time/60.0).round(2)} minutes) ", 96) + "🏁"
|
276
|
+
puts "🏁" + pad_to_width(" Demos completed: #{@total_demos} ", 96) + "🏁"
|
277
|
+
puts "🏁" + " " * 96 + "🏁"
|
278
|
+
puts "🏁" * 50
|
279
|
+
puts "\n"
|
280
|
+
|
281
|
+
puts "📋 WHAT YOU'VE SEEN:"
|
282
|
+
puts "=" * 80
|
283
|
+
puts "✅ Message deduplication and Dead Letter Queue patterns"
|
284
|
+
puts "✅ Point-to-point, publish-subscribe, and many-to-many messaging"
|
285
|
+
puts "✅ STDOUT transport for debugging and external integration"
|
286
|
+
puts "✅ Advanced message handlers (procs, blocks, lambdas)"
|
287
|
+
puts "✅ Comprehensive logging and error handling strategies"
|
288
|
+
puts "✅ Entity addressing and advanced message filtering"
|
289
|
+
puts "✅ Microservices communication patterns"
|
290
|
+
puts "✅ Configuration management and message inspection"
|
291
|
+
puts "\n"
|
292
|
+
|
293
|
+
puts "🚀 NEXT STEPS:"
|
294
|
+
puts "=" * 80
|
295
|
+
puts "• Explore individual demos: ruby examples/memory/<demo_file>"
|
296
|
+
puts "• Check out Redis Queue examples: examples/redis_queue/"
|
297
|
+
puts "• View comprehensive documentation: docs/"
|
298
|
+
puts "• Start building with SmartMessage in your projects!"
|
299
|
+
puts "\n"
|
300
|
+
|
301
|
+
puts "💡 For more information:"
|
302
|
+
puts " 📖 README.md - Getting started guide"
|
303
|
+
puts " 🔧 examples/memory/README.md - Detailed example descriptions"
|
304
|
+
puts " 📚 https://github.com/MadBomber/smart_message - Full documentation"
|
305
|
+
puts "\n"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# Allow running directly or requiring as a library
|
310
|
+
if __FILE__ == $0
|
311
|
+
puts "Starting SmartMessage Demo Suite..."
|
312
|
+
puts "Press Ctrl+C to interrupt at any time."
|
313
|
+
puts "\n"
|
314
|
+
|
315
|
+
runner = SmartMessageDemoRunner.new
|
316
|
+
runner.run_all
|
317
|
+
end
|
@@ -89,21 +89,13 @@ def demonstrate_deduplication
|
|
89
89
|
# Test 1: OrderMessage with deduplication
|
90
90
|
puts "--- Test 1: OrderMessage (with deduplication) ---"
|
91
91
|
|
92
|
-
#
|
93
|
-
header = SmartMessage::Header.new(
|
94
|
-
uuid: uuid,
|
95
|
-
message_class: "OrderMessage",
|
96
|
-
published_at: Time.now,
|
97
|
-
publisher_pid: Process.pid,
|
98
|
-
version: 1,
|
99
|
-
from: "order-service"
|
100
|
-
)
|
101
|
-
|
102
|
-
# First message
|
92
|
+
# First message (create normally, then set UUID for testing)
|
103
93
|
order1 = OrderMessage.new(
|
104
|
-
|
105
|
-
|
94
|
+
order_id: "ORD-001",
|
95
|
+
amount: 99.99
|
106
96
|
)
|
97
|
+
# Override UUID for deduplication testing
|
98
|
+
order1._sm_header.uuid = uuid
|
107
99
|
|
108
100
|
puts "Publishing first order message..."
|
109
101
|
order1.publish
|
@@ -111,9 +103,11 @@ def demonstrate_deduplication
|
|
111
103
|
|
112
104
|
# Second message with SAME UUID (should be deduplicated)
|
113
105
|
order2 = OrderMessage.new(
|
114
|
-
|
115
|
-
|
106
|
+
order_id: "ORD-002",
|
107
|
+
amount: 149.99
|
116
108
|
)
|
109
|
+
# Use same UUID to test deduplication
|
110
|
+
order2._sm_header.uuid = uuid
|
117
111
|
|
118
112
|
puts "Publishing duplicate order message (same UUID)..."
|
119
113
|
order2.publish
|
@@ -127,21 +121,13 @@ def demonstrate_deduplication
|
|
127
121
|
# Test 2: NotificationMessage without deduplication
|
128
122
|
puts "--- Test 2: NotificationMessage (no deduplication) ---"
|
129
123
|
|
130
|
-
#
|
131
|
-
notification_header = SmartMessage::Header.new(
|
132
|
-
uuid: uuid, # Same UUID as orders!
|
133
|
-
message_class: "NotificationMessage",
|
134
|
-
published_at: Time.now,
|
135
|
-
publisher_pid: Process.pid,
|
136
|
-
version: 1,
|
137
|
-
from: "notification-service"
|
138
|
-
)
|
139
|
-
|
140
|
-
# First notification
|
124
|
+
# First notification (create normally, then set UUID)
|
141
125
|
notif1 = NotificationMessage.new(
|
142
|
-
|
143
|
-
|
126
|
+
message: "Order confirmed",
|
127
|
+
recipient: "customer@example.com"
|
144
128
|
)
|
129
|
+
# Use same UUID as orders to show deduplication is per-message-class
|
130
|
+
notif1._sm_header.uuid = uuid
|
145
131
|
|
146
132
|
puts "Publishing first notification..."
|
147
133
|
notif1.publish
|
@@ -149,9 +135,11 @@ def demonstrate_deduplication
|
|
149
135
|
|
150
136
|
# Second notification with same UUID (should NOT be deduplicated)
|
151
137
|
notif2 = NotificationMessage.new(
|
152
|
-
|
153
|
-
|
138
|
+
message: "Order shipped",
|
139
|
+
recipient: "customer@example.com"
|
154
140
|
)
|
141
|
+
# Use same UUID - NotificationMessage doesn't have deduplication enabled
|
142
|
+
notif2._sm_header.uuid = uuid
|
155
143
|
|
156
144
|
puts "Publishing duplicate notification (same UUID)..."
|
157
145
|
notif2.publish
|
@@ -47,9 +47,9 @@ class PaymentMessage < SmartMessage::Base
|
|
47
47
|
transport SmartMessage::Transport.create(:memory)
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
header =
|
52
|
-
payload =
|
50
|
+
def process(message)
|
51
|
+
header = message._sm_header
|
52
|
+
payload = message
|
53
53
|
data = JSON.parse(payload, symbolize_names: true)
|
54
54
|
puts " 💳 Processing payment #{data[:payment_id]} for $#{data[:amount]}"
|
55
55
|
end
|
@@ -69,9 +69,9 @@ class OrderMessage < SmartMessage::Base
|
|
69
69
|
transport SmartMessage::Transport.create(:memory)
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
73
|
-
header =
|
74
|
-
payload =
|
72
|
+
def process(message)
|
73
|
+
header = message._sm_header
|
74
|
+
payload = message
|
75
75
|
data = JSON.parse(payload, symbolize_names: true)
|
76
76
|
puts " 📦 Processing order #{data[:order_id]} with #{data[:items].size} items"
|
77
77
|
end
|
@@ -90,9 +90,9 @@ class NotificationMessage < SmartMessage::Base
|
|
90
90
|
transport SmartMessage::Transport.create(:memory)
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
header =
|
95
|
-
payload =
|
93
|
+
def process(message)
|
94
|
+
header = message._sm_header
|
95
|
+
payload = message
|
96
96
|
data = JSON.parse(payload, symbolize_names: true)
|
97
97
|
puts " 📧 Sending #{data[:channel]} to user #{data[:user_id]}: #{data[:message]}"
|
98
98
|
end
|
@@ -35,7 +35,7 @@ class OrderMessage < SmartMessage::Base
|
|
35
35
|
|
36
36
|
# Configure to use memory transport for this example
|
37
37
|
config do
|
38
|
-
transport SmartMessage::Transport::
|
38
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
39
39
|
end
|
40
40
|
|
41
41
|
# Default processing - just logs the order
|
@@ -60,7 +60,7 @@ class PaymentResponseMessage < SmartMessage::Base
|
|
60
60
|
description: "ISO8601 timestamp when the payment was processed"
|
61
61
|
|
62
62
|
config do
|
63
|
-
transport SmartMessage::Transport::
|
63
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.process(message)
|
@@ -206,7 +206,7 @@ class OrderProcessingDemo
|
|
206
206
|
puts "• Point-to-point messaging between OrderService and PaymentService"
|
207
207
|
puts "• Bidirectional communication with request/response pattern"
|
208
208
|
puts "• JSON serialization of complex message data"
|
209
|
-
puts "•
|
209
|
+
puts "• Memory transport for local demonstration"
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
@@ -31,12 +31,12 @@ class UserEventMessage < SmartMessage::Base
|
|
31
31
|
description: "Additional event-specific data (source, location, IP, etc.)"
|
32
32
|
|
33
33
|
config do
|
34
|
-
transport SmartMessage::Transport::
|
34
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
35
35
|
end
|
36
36
|
|
37
37
|
# Default processor - just logs the event
|
38
|
-
def
|
39
|
-
message_header, message_payload =
|
38
|
+
def process(message)
|
39
|
+
message_header, message_payload = message
|
40
40
|
event_data = JSON.parse(message_payload)
|
41
41
|
puts "📡 Event broadcasted: #{event_data['event_type']} for user #{event_data['user_id']}"
|
42
42
|
end
|
@@ -50,13 +50,13 @@ class EmailService
|
|
50
50
|
UserEventMessage.subscribe('EmailService.handle_user_event')
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
53
|
+
def handle_event(message)
|
54
54
|
service = new
|
55
|
-
service.process_event(
|
55
|
+
service.process_event(message)
|
56
56
|
end
|
57
57
|
|
58
|
-
def process_event(
|
59
|
-
message_header, message_payload =
|
58
|
+
def process_event(message)
|
59
|
+
message_header, message_payload = message
|
60
60
|
event_data = JSON.parse(message_payload)
|
61
61
|
|
62
62
|
case event_data['event_type']
|
@@ -106,13 +106,13 @@ class SMSService
|
|
106
106
|
UserEventMessage.subscribe('SMSService.handle_user_event')
|
107
107
|
end
|
108
108
|
|
109
|
-
def
|
109
|
+
def handle_event(message)
|
110
110
|
service = new
|
111
|
-
service.process_event(
|
111
|
+
service.process_event(message)
|
112
112
|
end
|
113
113
|
|
114
|
-
def process_event(
|
115
|
-
message_header, message_payload =
|
114
|
+
def process_event(message)
|
115
|
+
message_header, message_payload = message
|
116
116
|
event_data = JSON.parse(message_payload)
|
117
117
|
|
118
118
|
case event_data['event_type']
|
@@ -172,18 +172,18 @@ class AuditService
|
|
172
172
|
UserEventMessage.subscribe('AuditService.handle_user_event')
|
173
173
|
end
|
174
174
|
|
175
|
-
def
|
175
|
+
def handle_event(message)
|
176
176
|
# Use a singleton pattern for persistent audit log
|
177
177
|
@@instance ||= new
|
178
|
-
@@instance.process_event(
|
178
|
+
@@instance.process_event(message)
|
179
179
|
end
|
180
180
|
|
181
181
|
def self.get_summary
|
182
182
|
@@instance&.get_audit_summary || {}
|
183
183
|
end
|
184
184
|
|
185
|
-
def process_event(
|
186
|
-
message_header, message_payload =
|
185
|
+
def process_event(message)
|
186
|
+
message_header, message_payload = message
|
187
187
|
event_data = JSON.parse(message_payload)
|
188
188
|
|
189
189
|
audit_entry = {
|
@@ -36,11 +36,11 @@ class ChatMessage < SmartMessage::Base
|
|
36
36
|
description: "Additional message data (reactions, edit history, etc.)"
|
37
37
|
|
38
38
|
config do
|
39
|
-
transport SmartMessage::Transport::
|
39
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
message_header, message_payload =
|
42
|
+
def process(message)
|
43
|
+
message_header, message_payload = message
|
44
44
|
chat_data = JSON.parse(message_payload)
|
45
45
|
puts "💬 Chat message in #{chat_data['room_id']}: #{chat_data['content']}"
|
46
46
|
end
|
@@ -64,11 +64,11 @@ class BotCommandMessage < SmartMessage::Base
|
|
64
64
|
description: "ISO8601 timestamp when command was issued"
|
65
65
|
|
66
66
|
config do
|
67
|
-
transport SmartMessage::Transport::
|
67
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
68
68
|
end
|
69
69
|
|
70
|
-
def
|
71
|
-
message_header, message_payload =
|
70
|
+
def process(message)
|
71
|
+
message_header, message_payload = message
|
72
72
|
command_data = JSON.parse(message_payload)
|
73
73
|
puts "🤖 Bot command: #{command_data['command']} in #{command_data['room_id']}"
|
74
74
|
end
|
@@ -92,11 +92,11 @@ class SystemNotificationMessage < SmartMessage::Base
|
|
92
92
|
description: "Additional system event data and context"
|
93
93
|
|
94
94
|
config do
|
95
|
-
transport SmartMessage::Transport::
|
95
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
96
96
|
end
|
97
97
|
|
98
|
-
def
|
99
|
-
message_header, message_payload =
|
98
|
+
def process(message)
|
99
|
+
message_header, message_payload = message
|
100
100
|
notif_data = JSON.parse(message_payload)
|
101
101
|
puts "🔔 System: #{notif_data['content']} in #{notif_data['room_id']}"
|
102
102
|
end
|
@@ -192,8 +192,8 @@ class HumanChatAgent
|
|
192
192
|
@@agents[agent.user_id] = agent
|
193
193
|
end
|
194
194
|
|
195
|
-
def
|
196
|
-
message_header, message_payload =
|
195
|
+
def handle_message(message)
|
196
|
+
message_header, message_payload = message
|
197
197
|
chat_data = JSON.parse(message_payload)
|
198
198
|
|
199
199
|
# Only process messages from rooms we're in and not our own messages
|
@@ -208,8 +208,8 @@ class HumanChatAgent
|
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
211
|
-
def handle_system_notification(
|
212
|
-
message_header, message_payload =
|
211
|
+
def handle_system_notification(message)
|
212
|
+
message_header, message_payload = message
|
213
213
|
notif_data = JSON.parse(message_payload)
|
214
214
|
|
215
215
|
# Only process notifications from rooms we're in
|
@@ -304,8 +304,8 @@ class BotAgent
|
|
304
304
|
)
|
305
305
|
end
|
306
306
|
|
307
|
-
def
|
308
|
-
message_header, message_payload =
|
307
|
+
def handle_command(message)
|
308
|
+
message_header, message_payload = message
|
309
309
|
command_data = JSON.parse(message_payload)
|
310
310
|
@@bots ||= []
|
311
311
|
|
@@ -318,8 +318,8 @@ class BotAgent
|
|
318
318
|
capable_bot&.process_command(command_data)
|
319
319
|
end
|
320
320
|
|
321
|
-
def
|
322
|
-
message_header, message_payload =
|
321
|
+
def handle_message(message)
|
322
|
+
message_header, message_payload = message
|
323
323
|
chat_data = JSON.parse(message_payload)
|
324
324
|
@@bots ||= []
|
325
325
|
|
@@ -495,8 +495,8 @@ class RoomManager
|
|
495
495
|
notification.publish
|
496
496
|
end
|
497
497
|
|
498
|
-
def
|
499
|
-
message_header, message_payload =
|
498
|
+
def handle_system_notification(message)
|
499
|
+
message_header, message_payload = message
|
500
500
|
@@instance ||= new
|
501
501
|
@@instance.process_system_notification(message_header, message_payload)
|
502
502
|
end
|