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,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::
|
31
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
32
32
|
end
|
33
33
|
|
34
34
|
# Default handler
|
35
|
-
def
|
36
|
-
message_header, message_payload =
|
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 |
|
60
|
-
data =
|
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 |
|
72
|
-
data =
|
73
|
-
timestamp =
|
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 |
|
84
|
-
data =
|
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
|
98
|
-
data =
|
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 { |
|
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)"
|