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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +120 -0
  4. data/Gemfile.lock +3 -3
  5. data/README.md +71 -25
  6. data/docs/index.md +2 -0
  7. data/docs/reference/transports.md +46 -21
  8. data/docs/transports/memory-transport.md +2 -1
  9. data/docs/transports/multi-transport.md +484 -0
  10. data/examples/file/00_run_all_file_demos.rb +260 -0
  11. data/examples/file/01_basic_file_transport_demo.rb +237 -0
  12. data/examples/file/02_fifo_transport_demo.rb +289 -0
  13. data/examples/file/03_file_watching_demo.rb +332 -0
  14. data/examples/file/04_multi_transport_file_demo.rb +432 -0
  15. data/examples/file/README.md +257 -0
  16. data/examples/memory/00_run_all_demos.rb +317 -0
  17. data/examples/memory/01_message_deduplication_demo.rb +18 -30
  18. data/examples/memory/02_dead_letter_queue_demo.rb +9 -9
  19. data/examples/memory/03_point_to_point_orders.rb +3 -3
  20. data/examples/memory/04_publish_subscribe_events.rb +15 -15
  21. data/examples/memory/05_many_to_many_chat.rb +19 -19
  22. data/examples/memory/06_stdout_publish_only.rb +145 -0
  23. data/examples/memory/07_proc_handlers_demo.rb +13 -13
  24. data/examples/memory/08_custom_logger_demo.rb +136 -136
  25. data/examples/memory/09_error_handling_demo.rb +7 -7
  26. data/examples/memory/10_entity_addressing_basic.rb +25 -25
  27. data/examples/memory/11_entity_addressing_with_filtering.rb +32 -32
  28. data/examples/memory/12_regex_filtering_microservices.rb +10 -10
  29. data/examples/memory/14_global_configuration_demo.rb +12 -12
  30. data/examples/memory/README.md +34 -17
  31. data/examples/memory/log/demo_app.log.1 +100 -0
  32. data/examples/memory/log/demo_app.log.2 +100 -0
  33. data/examples/multi_transport_example.rb +114 -0
  34. data/examples/redis/01_smart_home_iot_demo.rb +20 -20
  35. data/examples/utilities/box_it.rb +12 -0
  36. data/examples/utilities/doing.rb +19 -0
  37. data/examples/utilities/temp.md +28 -0
  38. data/lib/smart_message/base.rb +5 -7
  39. data/lib/smart_message/errors.rb +3 -0
  40. data/lib/smart_message/header.rb +1 -1
  41. data/lib/smart_message/logger/default.rb +1 -1
  42. data/lib/smart_message/messaging.rb +36 -6
  43. data/lib/smart_message/plugins.rb +46 -4
  44. data/lib/smart_message/serializer/base.rb +1 -1
  45. data/lib/smart_message/serializer.rb +3 -2
  46. data/lib/smart_message/subscription.rb +18 -20
  47. data/lib/smart_message/transport/async_publish_queue.rb +284 -0
  48. data/lib/smart_message/transport/fifo_operations.rb +264 -0
  49. data/lib/smart_message/transport/file_operations.rb +200 -0
  50. data/lib/smart_message/transport/file_transport.rb +149 -0
  51. data/lib/smart_message/transport/file_watching.rb +72 -0
  52. data/lib/smart_message/transport/partitioned_files.rb +46 -0
  53. data/lib/smart_message/transport/stdout_transport.rb +50 -36
  54. data/lib/smart_message/transport/stdout_transport.rb.backup +88 -0
  55. data/lib/smart_message/version.rb +1 -1
  56. metadata +24 -10
  57. data/ideas/README.md +0 -41
  58. data/ideas/agents.md +0 -1001
  59. data/ideas/database_transport.md +0 -980
  60. data/ideas/improvement.md +0 -359
  61. data/ideas/meshage.md +0 -1788
  62. data/ideas/message_discovery.md +0 -178
  63. data/ideas/message_schema.md +0 -1381
  64. data/lib/smart_message/wrapper.rb.bak +0 -132
  65. /data/examples/memory/{06_pretty_print_demo.rb → 16_pretty_print_demo.rb} +0 -0
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ # examples/memory/06_stdout_publish_only.rb
3
+ #
4
+ # STDOUT Transport Example - Publish Only
5
+ #
6
+ # This example demonstrates the STDOUT transport which is designed for
7
+ # publish-only scenarios - great for debugging, logging, or one-way
8
+ # message output without local processing.
9
+
10
+ require_relative '../../lib/smart_message'
11
+
12
+ puts "=== SmartMessage Example: STDOUT Transport (Publish Only) ==="
13
+ puts
14
+
15
+ # Configure SmartMessage for this example
16
+ SmartMessage.configure do |config|
17
+ config.logger = STDERR # Use STDERR for framework logs so STDOUT is clean
18
+ config.log_level = :warn # Reduce noise
19
+ end
20
+
21
+ # Define a Log Message for one-way output
22
+ class LogMessage < SmartMessage::Base
23
+ description "Log entries that are output to STDOUT for external processing"
24
+
25
+ property :level,
26
+ description: "Log level (info, warn, error, debug)"
27
+ property :component,
28
+ description: "Component or service generating the log"
29
+ property :message,
30
+ description: "Human-readable log message"
31
+ property :timestamp,
32
+ default: -> { Time.now.iso8601 },
33
+ description: "ISO8601 timestamp of when log was generated"
34
+ property :context,
35
+ description: "Optional additional context data"
36
+
37
+ # Configure to use STDOUT transport (publish-only)
38
+ config do
39
+ transport SmartMessage::Transport::StdoutTransport.new
40
+ from 'log-service'
41
+ end
42
+ end
43
+
44
+ # Define a Metrics Message for monitoring systems
45
+ class MetricsMessage < SmartMessage::Base
46
+ description "System metrics published to STDOUT for monitoring ingestion"
47
+
48
+ property :metric_name,
49
+ description: "Name of the metric (e.g., 'cpu_usage', 'memory_usage')"
50
+ property :value,
51
+ description: "Numeric value of the metric"
52
+ property :unit,
53
+ description: "Unit of measurement (%, MB, requests/sec, etc.)"
54
+ property :tags,
55
+ description: "Hash of tags for metric categorization"
56
+ property :timestamp,
57
+ default: -> { Time.now.to_i },
58
+ description: "Unix timestamp of metric collection"
59
+
60
+ config do
61
+ transport SmartMessage::Transport::StdoutTransport.new(format: :json) # JSON format for metrics
62
+ from 'metrics-collector'
63
+ end
64
+ end
65
+
66
+ puts "šŸ“ Publishing log messages to STDOUT..."
67
+ puts "=" * 50
68
+
69
+ # Create and publish various log messages
70
+ log_messages = [
71
+ {
72
+ level: "info",
73
+ component: "user-service",
74
+ message: "User authentication successful",
75
+ context: { user_id: 12345, ip_address: "192.168.1.100" }
76
+ },
77
+ {
78
+ level: "warn",
79
+ component: "payment-service",
80
+ message: "Payment processing took longer than expected",
81
+ context: { order_id: "ORD-001", processing_time_ms: 5500 }
82
+ },
83
+ {
84
+ level: "error",
85
+ component: "database-service",
86
+ message: "Connection pool exhausted",
87
+ context: { pool_size: 20, active_connections: 20, queue_length: 15 }
88
+ }
89
+ ]
90
+
91
+ log_messages.each do |log_data|
92
+ message = LogMessage.new(**log_data)
93
+ message.publish
94
+ sleep(0.5) # Small delay for readability
95
+ end
96
+
97
+ puts "\nšŸ“Š Publishing metrics to STDOUT (JSON format)..."
98
+ puts "=" * 50
99
+
100
+ # Create and publish system metrics
101
+ metrics_data = [
102
+ {
103
+ metric_name: "cpu_usage",
104
+ value: 67.5,
105
+ unit: "%",
106
+ tags: { host: "web-01", environment: "production" }
107
+ },
108
+ {
109
+ metric_name: "memory_usage",
110
+ value: 2048,
111
+ unit: "MB",
112
+ tags: { host: "web-01", environment: "production" }
113
+ },
114
+ {
115
+ metric_name: "requests_per_second",
116
+ value: 125,
117
+ unit: "req/sec",
118
+ tags: { service: "api-gateway", endpoint: "/api/users" }
119
+ }
120
+ ]
121
+
122
+ metrics_data.each do |metric_data|
123
+ message = MetricsMessage.new(**metric_data)
124
+ message.publish
125
+ sleep(0.3)
126
+ end
127
+
128
+ puts "\n" + "=" * 50
129
+ puts "šŸ” Key Points About STDOUT Transport:"
130
+ puts " āœ“ Publish-only: No message processing"
131
+ puts " āœ“ Perfect for logging and debugging scenarios"
132
+ puts " āœ“ Great for integration with external systems"
133
+ puts " āœ“ Supports both pretty-print and JSON formats"
134
+ puts " āœ“ Clean separation: output to STDOUT, logs to STDERR"
135
+ puts " āœ“ Subscription attempts are ignored with warnings"
136
+
137
+ puts "\nšŸ’” Usage Ideas:"
138
+ puts " • Debug message flow: ./my_app | grep 'MessageClass'"
139
+ puts " • Feed log aggregators: ./my_app | fluentd"
140
+ puts " • Pipe to analysis tools: ./my_app | jq '.metric_name'"
141
+ puts " • Integration testing: capture and verify output"
142
+ puts " • Development monitoring: real-time message visibility"
143
+
144
+ puts "\nāš ļø Note: If you need local message processing, use MemoryTransport instead!"
145
+ puts "=" * 80
@@ -28,12 +28,12 @@ class NotificationMessage < SmartMessage::Base
28
28
  description: "ISO8601 timestamp when notification was created"
29
29
 
30
30
  config do
31
- transport SmartMessage::Transport::StdoutTransport.new(loopback: true)
31
+ transport SmartMessage::Transport::MemoryTransport.new
32
32
  end
33
33
 
34
34
  # Default handler
35
- def self.process(wrapper)
36
- message_header, message_payload = wrapper.split
35
+ def process(message)
36
+ message_header, message_payload = message
37
37
  data = JSON.parse(message_payload)
38
38
  icon = case data['type']
39
39
  when 'info' then 'ā„¹ļø'
@@ -56,8 +56,8 @@ puts
56
56
 
57
57
  # 2. Block handler
58
58
  puts "2ļøāƒ£ Block handler subscription:"
59
- block_id = NotificationMessage.subscribe do |wrapper|
60
- data = JSON.parse(wrapper._sm_payload)
59
+ block_id = NotificationMessage.subscribe do |message|
60
+ data = message
61
61
  if data['type'] == 'error'
62
62
  puts "šŸ”„ [BLOCK] Critical error logged: #{data['title']}"
63
63
  # Could send to error tracking service here
@@ -68,9 +68,9 @@ puts
68
68
 
69
69
  # 3. Proc handler
70
70
  puts "3ļøāƒ£ Proc handler subscription:"
71
- audit_logger = proc do |wrapper|
72
- data = JSON.parse(wrapper._sm_payload)
73
- timestamp = wrapper._sm_header.published_at.strftime('%Y-%m-%d %H:%M:%S')
71
+ audit_logger = proc do |message|
72
+ data = message
73
+ timestamp = message._sm_header.published_at.strftime('%Y-%m-%d %H:%M:%S')
74
74
  puts "šŸ“ [AUDIT] #{timestamp} - User #{data['user_id']}: #{data['type'].upcase}"
75
75
  end
76
76
 
@@ -80,8 +80,8 @@ puts
80
80
 
81
81
  # 4. Lambda handler
82
82
  puts "4ļøāƒ£ Lambda handler subscription:"
83
- warning_filter = lambda do |wrapper|
84
- data = JSON.parse(wrapper._sm_payload)
83
+ warning_filter = lambda do |message|
84
+ data = message
85
85
  if data['type'] == 'warning'
86
86
  puts "⚔ [LAMBDA] Warning for user #{data['user_id']}: #{data['message']}"
87
87
  end
@@ -94,8 +94,8 @@ puts
94
94
  # 5. Method handler (traditional, but shown for comparison)
95
95
  puts "5ļøāƒ£ Method handler subscription:"
96
96
  class NotificationService
97
- def self.handle_notifications(wrapper)
98
- data = JSON.parse(wrapper._sm_payload)
97
+ def handle_notifications(message)
98
+ data = message
99
99
  puts "šŸ¢ [SERVICE] Processing #{data['type']} notification for user #{data['user_id']}"
100
100
  end
101
101
  end
@@ -174,7 +174,7 @@ puts "=" * 60
174
174
 
175
175
  puts "\nThis example demonstrated:"
176
176
  puts "• āœ… Default self.process method (traditional)"
177
- puts "• āœ… Block handlers with subscribe { |wrapper| ... } (NEW!)"
177
+ puts "• āœ… Block handlers with subscribe { |message| ... } (NEW!)"
178
178
  puts "• āœ… Proc handlers with subscribe(proc { ... }) (NEW!)"
179
179
  puts "• āœ… Lambda handlers with subscribe(lambda { ... }) (NEW!)"
180
180
  puts "• āœ… Method handlers with subscribe('Class.method') (traditional)"