smart_message 0.0.13 ā 0.0.17
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 +184 -0
- data/Gemfile.lock +6 -6
- data/README.md +75 -25
- data/docs/guides/transport-selection.md +361 -0
- data/docs/index.md +2 -0
- data/docs/reference/transports.md +78 -29
- data/docs/transports/file-transport.md +535 -0
- data/docs/transports/memory-transport.md +2 -1
- data/docs/transports/multi-transport.md +484 -0
- data/docs/transports/redis-transport.md +1 -1
- data/docs/transports/stdout-transport.md +580 -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 +118 -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.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 +232 -0
- data/lib/smart_message/transport/file_transport.rb +152 -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 +7 -81
- data/lib/smart_message/transport/stdout_transport.rb.backup +88 -0
- data/lib/smart_message/version.rb +1 -1
- data/mkdocs.yml +4 -5
- metadata +26 -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,118 @@
|
|
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 with different formats
|
7
|
+
# using a single message class that can be configured with different
|
8
|
+
# transport instances.
|
9
|
+
|
10
|
+
require_relative '../../lib/smart_message'
|
11
|
+
|
12
|
+
puts "=== SmartMessage Example: STDOUT Transport Format Demonstrations ==="
|
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 simple message class for format demonstration
|
22
|
+
class DemoMessage < SmartMessage::Base
|
23
|
+
description "Simple demonstration message for format testing"
|
24
|
+
|
25
|
+
property :first_name,
|
26
|
+
description: "Person's first name"
|
27
|
+
property :last_name,
|
28
|
+
description: "Person's last name"
|
29
|
+
|
30
|
+
# Default config - will be overridden with transport instance replacement
|
31
|
+
config do
|
32
|
+
transport SmartMessage::Transport::StdoutTransport.new
|
33
|
+
from 'demo-service'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
puts "šØ Example 1: Pretty Format (:pretty) - 1 message"
|
38
|
+
puts "=" * 60
|
39
|
+
|
40
|
+
# Create a simple message for pretty formatting
|
41
|
+
message_data = {
|
42
|
+
first_name: "Alice",
|
43
|
+
last_name: "Johnson"
|
44
|
+
}
|
45
|
+
|
46
|
+
# Replace the message's transport with :pretty format
|
47
|
+
message = DemoMessage.new(**message_data)
|
48
|
+
message.transport SmartMessage::Transport::StdoutTransport.new(format: :pretty)
|
49
|
+
message.publish
|
50
|
+
|
51
|
+
puts
|
52
|
+
puts
|
53
|
+
puts "š Example 2: JSONL Format (:jsonl) - 2 messages"
|
54
|
+
puts "=" * 60
|
55
|
+
|
56
|
+
# Create two simple messages for JSONL format
|
57
|
+
jsonl_messages = [
|
58
|
+
{
|
59
|
+
first_name: "Bob",
|
60
|
+
last_name: "Smith"
|
61
|
+
},
|
62
|
+
{
|
63
|
+
first_name: "Carol",
|
64
|
+
last_name: "Williams"
|
65
|
+
}
|
66
|
+
]
|
67
|
+
|
68
|
+
# Replace transport with :jsonl format and publish both messages
|
69
|
+
jsonl_messages.each do |msg_data|
|
70
|
+
message = DemoMessage.new(**msg_data)
|
71
|
+
message.transport SmartMessage::Transport::StdoutTransport.new(format: :jsonl)
|
72
|
+
message.publish
|
73
|
+
end
|
74
|
+
|
75
|
+
puts
|
76
|
+
puts
|
77
|
+
puts "š Example 3: JSON Format (:json) - 3 messages"
|
78
|
+
puts "=" * 60
|
79
|
+
|
80
|
+
# Create three simple messages for JSON format
|
81
|
+
json_messages = [
|
82
|
+
{
|
83
|
+
first_name: "David",
|
84
|
+
last_name: "Brown"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
first_name: "Emma",
|
88
|
+
last_name: "Davis"
|
89
|
+
},
|
90
|
+
{
|
91
|
+
first_name: "Frank",
|
92
|
+
last_name: "Miller"
|
93
|
+
}
|
94
|
+
]
|
95
|
+
|
96
|
+
# Replace transport with :json format and publish all three messages
|
97
|
+
json_messages.each do |msg_data|
|
98
|
+
message = DemoMessage.new(**msg_data)
|
99
|
+
message.transport SmartMessage::Transport::StdoutTransport.new(format: :json)
|
100
|
+
message.publish
|
101
|
+
end
|
102
|
+
|
103
|
+
puts
|
104
|
+
puts
|
105
|
+
puts "\nš Format Comparison Summary:"
|
106
|
+
puts " šØ :pretty - Beautiful, colorized output using amazing_print"
|
107
|
+
puts " š :jsonl - JSON Lines format, one message per line (default)"
|
108
|
+
puts " š :json - Compact JSON format without newlines"
|
109
|
+
puts
|
110
|
+
puts "š” Usage Ideas:"
|
111
|
+
puts " ⢠Debug message flow: ./my_app | grep 'first_name'"
|
112
|
+
puts " ⢠Feed log aggregators: ./my_app | fluentd"
|
113
|
+
puts " ⢠Pipe to analysis tools: ./my_app | jq '.last_name'"
|
114
|
+
puts " ⢠Integration testing: capture and verify output"
|
115
|
+
puts " ⢠Development monitoring: real-time message visibility"
|
116
|
+
puts
|
117
|
+
puts "ā ļø Note: If you need local message processing, use MemoryTransport instead!"
|
118
|
+
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)"
|