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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +184 -0
  4. data/Gemfile.lock +6 -6
  5. data/README.md +75 -25
  6. data/docs/guides/transport-selection.md +361 -0
  7. data/docs/index.md +2 -0
  8. data/docs/reference/transports.md +78 -29
  9. data/docs/transports/file-transport.md +535 -0
  10. data/docs/transports/memory-transport.md +2 -1
  11. data/docs/transports/multi-transport.md +484 -0
  12. data/docs/transports/redis-transport.md +1 -1
  13. data/docs/transports/stdout-transport.md +580 -0
  14. data/examples/file/00_run_all_file_demos.rb +260 -0
  15. data/examples/file/01_basic_file_transport_demo.rb +237 -0
  16. data/examples/file/02_fifo_transport_demo.rb +289 -0
  17. data/examples/file/03_file_watching_demo.rb +332 -0
  18. data/examples/file/04_multi_transport_file_demo.rb +432 -0
  19. data/examples/file/README.md +257 -0
  20. data/examples/memory/00_run_all_demos.rb +317 -0
  21. data/examples/memory/01_message_deduplication_demo.rb +18 -30
  22. data/examples/memory/02_dead_letter_queue_demo.rb +9 -9
  23. data/examples/memory/03_point_to_point_orders.rb +3 -3
  24. data/examples/memory/04_publish_subscribe_events.rb +15 -15
  25. data/examples/memory/05_many_to_many_chat.rb +19 -19
  26. data/examples/memory/06_stdout_publish_only.rb +118 -0
  27. data/examples/memory/07_proc_handlers_demo.rb +13 -13
  28. data/examples/memory/08_custom_logger_demo.rb +136 -136
  29. data/examples/memory/09_error_handling_demo.rb +7 -7
  30. data/examples/memory/10_entity_addressing_basic.rb +25 -25
  31. data/examples/memory/11_entity_addressing_with_filtering.rb +32 -32
  32. data/examples/memory/12_regex_filtering_microservices.rb +10 -10
  33. data/examples/memory/14_global_configuration_demo.rb +12 -12
  34. data/examples/memory/README.md +34 -17
  35. data/examples/memory/log/demo_app.log.2 +100 -0
  36. data/examples/multi_transport_example.rb +114 -0
  37. data/examples/redis/01_smart_home_iot_demo.rb +20 -20
  38. data/examples/utilities/box_it.rb +12 -0
  39. data/examples/utilities/doing.rb +19 -0
  40. data/examples/utilities/temp.md +28 -0
  41. data/lib/smart_message/base.rb +5 -7
  42. data/lib/smart_message/errors.rb +3 -0
  43. data/lib/smart_message/header.rb +1 -1
  44. data/lib/smart_message/logger/default.rb +1 -1
  45. data/lib/smart_message/messaging.rb +36 -6
  46. data/lib/smart_message/plugins.rb +46 -4
  47. data/lib/smart_message/serializer/base.rb +1 -1
  48. data/lib/smart_message/serializer.rb +3 -2
  49. data/lib/smart_message/subscription.rb +18 -20
  50. data/lib/smart_message/transport/async_publish_queue.rb +284 -0
  51. data/lib/smart_message/transport/fifo_operations.rb +264 -0
  52. data/lib/smart_message/transport/file_operations.rb +232 -0
  53. data/lib/smart_message/transport/file_transport.rb +152 -0
  54. data/lib/smart_message/transport/file_watching.rb +72 -0
  55. data/lib/smart_message/transport/partitioned_files.rb +46 -0
  56. data/lib/smart_message/transport/stdout_transport.rb +7 -81
  57. data/lib/smart_message/transport/stdout_transport.rb.backup +88 -0
  58. data/lib/smart_message/version.rb +1 -1
  59. data/mkdocs.yml +4 -5
  60. metadata +26 -10
  61. data/ideas/README.md +0 -41
  62. data/ideas/agents.md +0 -1001
  63. data/ideas/database_transport.md +0 -980
  64. data/ideas/improvement.md +0 -359
  65. data/ideas/meshage.md +0 -1788
  66. data/ideas/message_discovery.md +0 -178
  67. data/ideas/message_schema.md +0 -1381
  68. data/lib/smart_message/wrapper.rb.bak +0 -132
  69. /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::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)"