smart_message 0.0.12 → 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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +155 -1
  4. data/Gemfile.lock +6 -6
  5. data/README.md +71 -25
  6. data/docs/core-concepts/architecture.md +5 -10
  7. data/docs/getting-started/examples.md +0 -12
  8. data/docs/getting-started/quick-start.md +4 -9
  9. data/docs/index.md +6 -4
  10. data/docs/reference/serializers.md +160 -488
  11. data/docs/reference/transports.md +47 -146
  12. data/docs/transports/memory-transport.md +2 -1
  13. data/docs/transports/multi-transport.md +484 -0
  14. data/docs/transports/redis-transport-comparison.md +215 -350
  15. data/docs/transports/redis-transport.md +3 -22
  16. data/examples/README.md +6 -9
  17. data/examples/city_scenario/README.md +1 -1
  18. data/examples/city_scenario/messages/emergency_911_message.rb +0 -1
  19. data/examples/city_scenario/messages/emergency_resolved_message.rb +0 -1
  20. data/examples/city_scenario/messages/fire_dispatch_message.rb +0 -1
  21. data/examples/city_scenario/messages/fire_emergency_message.rb +0 -1
  22. data/examples/city_scenario/messages/health_check_message.rb +0 -1
  23. data/examples/city_scenario/messages/health_status_message.rb +0 -1
  24. data/examples/city_scenario/messages/police_dispatch_message.rb +0 -1
  25. data/examples/city_scenario/messages/silent_alarm_message.rb +0 -1
  26. data/examples/file/00_run_all_file_demos.rb +260 -0
  27. data/examples/file/01_basic_file_transport_demo.rb +237 -0
  28. data/examples/file/02_fifo_transport_demo.rb +289 -0
  29. data/examples/file/03_file_watching_demo.rb +332 -0
  30. data/examples/file/04_multi_transport_file_demo.rb +432 -0
  31. data/examples/file/README.md +257 -0
  32. data/examples/memory/00_run_all_demos.rb +317 -0
  33. data/examples/memory/01_message_deduplication_demo.rb +18 -32
  34. data/examples/memory/02_dead_letter_queue_demo.rb +9 -12
  35. data/examples/memory/03_point_to_point_orders.rb +3 -5
  36. data/examples/memory/04_publish_subscribe_events.rb +15 -16
  37. data/examples/memory/05_many_to_many_chat.rb +19 -22
  38. data/examples/memory/06_stdout_publish_only.rb +145 -0
  39. data/examples/memory/07_proc_handlers_demo.rb +13 -14
  40. data/examples/memory/08_custom_logger_demo.rb +136 -140
  41. data/examples/memory/09_error_handling_demo.rb +7 -10
  42. data/examples/memory/10_entity_addressing_basic.rb +25 -31
  43. data/examples/memory/11_entity_addressing_with_filtering.rb +32 -36
  44. data/examples/memory/12_regex_filtering_microservices.rb +10 -11
  45. data/examples/memory/13_header_block_configuration.rb +0 -5
  46. data/examples/memory/14_global_configuration_demo.rb +12 -14
  47. data/examples/memory/15_logger_demo.rb +0 -1
  48. data/examples/memory/README.md +37 -20
  49. data/examples/memory/log/demo_app.log.1 +100 -0
  50. data/examples/memory/log/demo_app.log.2 +100 -0
  51. data/examples/multi_transport_example.rb +114 -0
  52. data/examples/redis/01_smart_home_iot_demo.rb +20 -24
  53. data/examples/redis/README.md +0 -2
  54. data/examples/utilities/box_it.rb +12 -0
  55. data/examples/utilities/doing.rb +19 -0
  56. data/examples/utilities/temp.md +28 -0
  57. data/lib/smart_message/base.rb +24 -17
  58. data/lib/smart_message/configuration.rb +2 -23
  59. data/lib/smart_message/dead_letter_queue.rb +1 -1
  60. data/lib/smart_message/errors.rb +3 -0
  61. data/lib/smart_message/header.rb +1 -1
  62. data/lib/smart_message/logger/default.rb +1 -1
  63. data/lib/smart_message/messaging.rb +37 -66
  64. data/lib/smart_message/plugins.rb +42 -41
  65. data/lib/smart_message/serializer/base.rb +1 -1
  66. data/lib/smart_message/serializer.rb +3 -2
  67. data/lib/smart_message/subscription.rb +18 -20
  68. data/lib/smart_message/transport/async_publish_queue.rb +284 -0
  69. data/lib/smart_message/transport/base.rb +42 -8
  70. data/lib/smart_message/transport/fifo_operations.rb +264 -0
  71. data/lib/smart_message/transport/file_operations.rb +200 -0
  72. data/lib/smart_message/transport/file_transport.rb +149 -0
  73. data/lib/smart_message/transport/file_watching.rb +72 -0
  74. data/lib/smart_message/transport/memory_transport.rb +23 -4
  75. data/lib/smart_message/transport/partitioned_files.rb +46 -0
  76. data/lib/smart_message/transport/redis_transport.rb +11 -0
  77. data/lib/smart_message/transport/registry.rb +0 -1
  78. data/lib/smart_message/transport/stdout_transport.rb +73 -41
  79. data/lib/smart_message/transport/stdout_transport.rb.backup +88 -0
  80. data/lib/smart_message/transport.rb +0 -1
  81. data/lib/smart_message/version.rb +1 -1
  82. metadata +25 -37
  83. data/docs/guides/redis-queue-getting-started.md +0 -697
  84. data/docs/guides/redis-queue-patterns.md +0 -889
  85. data/docs/guides/redis-queue-production.md +0 -1091
  86. data/docs/transports/redis-enhanced-transport.md +0 -524
  87. data/docs/transports/redis-queue-transport.md +0 -1304
  88. data/examples/redis_enhanced/README.md +0 -319
  89. data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +0 -233
  90. data/examples/redis_enhanced/enhanced_02_fluent_api.rb +0 -331
  91. data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +0 -281
  92. data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +0 -419
  93. data/examples/redis_queue/01_basic_messaging.rb +0 -221
  94. data/examples/redis_queue/01_comprehensive_examples.rb +0 -508
  95. data/examples/redis_queue/02_pattern_routing.rb +0 -405
  96. data/examples/redis_queue/03_fluent_api.rb +0 -422
  97. data/examples/redis_queue/04_load_balancing.rb +0 -486
  98. data/examples/redis_queue/05_microservices.rb +0 -735
  99. data/examples/redis_queue/06_emergency_alerts.rb +0 -777
  100. data/examples/redis_queue/07_queue_management.rb +0 -587
  101. data/examples/redis_queue/README.md +0 -366
  102. data/examples/redis_queue/enhanced_01_basic_patterns.rb +0 -233
  103. data/examples/redis_queue/enhanced_02_fluent_api.rb +0 -331
  104. data/examples/redis_queue/enhanced_03_dual_publishing.rb +0 -281
  105. data/examples/redis_queue/enhanced_04_advanced_routing.rb +0 -419
  106. data/examples/redis_queue/redis_queue_architecture.svg +0 -148
  107. data/ideas/README.md +0 -41
  108. data/ideas/agents.md +0 -1001
  109. data/ideas/database_transport.md +0 -980
  110. data/ideas/improvement.md +0 -359
  111. data/ideas/meshage.md +0 -1788
  112. data/ideas/message_discovery.md +0 -178
  113. data/ideas/message_schema.md +0 -1381
  114. data/lib/smart_message/transport/redis_enhanced_transport.rb +0 -399
  115. data/lib/smart_message/transport/redis_queue_transport.rb +0 -555
  116. data/lib/smart_message/wrapper.rb.bak +0 -132
  117. /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,13 +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)
32
- serializer SmartMessage::Serializer::Json.new
31
+ transport SmartMessage::Transport::MemoryTransport.new
33
32
  end
34
33
 
35
34
  # Default handler
36
- def self.process(wrapper)
37
- message_header, message_payload = wrapper.split
35
+ def process(message)
36
+ message_header, message_payload = message
38
37
  data = JSON.parse(message_payload)
39
38
  icon = case data['type']
40
39
  when 'info' then 'ā„¹ļø'
@@ -57,8 +56,8 @@ puts
57
56
 
58
57
  # 2. Block handler
59
58
  puts "2ļøāƒ£ Block handler subscription:"
60
- block_id = NotificationMessage.subscribe do |wrapper|
61
- data = JSON.parse(wrapper._sm_payload)
59
+ block_id = NotificationMessage.subscribe do |message|
60
+ data = message
62
61
  if data['type'] == 'error'
63
62
  puts "šŸ”„ [BLOCK] Critical error logged: #{data['title']}"
64
63
  # Could send to error tracking service here
@@ -69,9 +68,9 @@ puts
69
68
 
70
69
  # 3. Proc handler
71
70
  puts "3ļøāƒ£ Proc handler subscription:"
72
- audit_logger = proc do |wrapper|
73
- data = JSON.parse(wrapper._sm_payload)
74
- 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')
75
74
  puts "šŸ“ [AUDIT] #{timestamp} - User #{data['user_id']}: #{data['type'].upcase}"
76
75
  end
77
76
 
@@ -81,8 +80,8 @@ puts
81
80
 
82
81
  # 4. Lambda handler
83
82
  puts "4ļøāƒ£ Lambda handler subscription:"
84
- warning_filter = lambda do |wrapper|
85
- data = JSON.parse(wrapper._sm_payload)
83
+ warning_filter = lambda do |message|
84
+ data = message
86
85
  if data['type'] == 'warning'
87
86
  puts "⚔ [LAMBDA] Warning for user #{data['user_id']}: #{data['message']}"
88
87
  end
@@ -95,8 +94,8 @@ puts
95
94
  # 5. Method handler (traditional, but shown for comparison)
96
95
  puts "5ļøāƒ£ Method handler subscription:"
97
96
  class NotificationService
98
- def self.handle_notifications(wrapper)
99
- data = JSON.parse(wrapper._sm_payload)
97
+ def handle_notifications(message)
98
+ data = message
100
99
  puts "šŸ¢ [SERVICE] Processing #{data['type']} notification for user #{data['user_id']}"
101
100
  end
102
101
  end
@@ -175,7 +174,7 @@ puts "=" * 60
175
174
 
176
175
  puts "\nThis example demonstrated:"
177
176
  puts "• āœ… Default self.process method (traditional)"
178
- puts "• āœ… Block handlers with subscribe { |wrapper| ... } (NEW!)"
177
+ puts "• āœ… Block handlers with subscribe { |message| ... } (NEW!)"
179
178
  puts "• āœ… Proc handlers with subscribe(proc { ... }) (NEW!)"
180
179
  puts "• āœ… Lambda handlers with subscribe(lambda { ... }) (NEW!)"
181
180
  puts "• āœ… Method handlers with subscribe('Class.method') (traditional)"