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
@@ -2,70 +2,102 @@
2
2
  # encoding: utf-8
3
3
  # frozen_string_literal: true
4
4
 
5
+ require_relative 'file_transport'
6
+
5
7
  module SmartMessage
6
8
  module Transport
7
9
  # STDOUT transport for testing and development
8
- # This transport outputs messages to STDOUT and optionally loops them back
9
- class StdoutTransport < Base
10
- def default_options
11
- {
12
- loopback: false,
13
- output: $stdout
10
+ # This is a publish-only transport that outputs messages to STDOUT
11
+ # Now inherits from FileTransport but maintains specialized formatting
12
+ class StdoutTransport < FileTransport
13
+ def initialize(options = {})
14
+ # Merge STDOUT-specific defaults with FileTransport defaults
15
+ stdout_options = {
16
+ file_path: $stdout,
17
+ file_mode: 'w',
18
+ file_type: :regular,
19
+ format: :pretty, # :pretty or :json
20
+ enable_subscriptions: false, # STDOUT is publish-only
21
+ auto_flush: true
14
22
  }
23
+ super(stdout_options.merge(options))
15
24
  end
16
25
 
26
+ # Default to JSON for readability in STDOUT
27
+ def default_serializer
28
+ SmartMessage::Serializer::Json.new
29
+ end
30
+
31
+ # Override configuration to handle STDOUT-specific setup
17
32
  def configure
18
- @output = @options[:output].is_a?(String) ? File.open(@options[:output], 'w') : @options[:output]
33
+ # If file_path is a string, delegate to parent FileTransport
34
+ if @options[:file_path].is_a?(String)
35
+ super
36
+ else
37
+ # Use the IO object directly (like $stdout)
38
+ @file_handle = @options[:file_path]
39
+ @write_buffer = []
40
+ @last_flush = Time.now
41
+ @file_mutex = Mutex.new
42
+ end
19
43
  end
20
-
21
- # Enable/disable loopback mode
22
- def loopback=(enabled)
23
- @options[:loopback] = enabled
44
+
45
+ # Override write_to_file to handle STDOUT directly
46
+ def write_to_file(serialized_message)
47
+ # If using a string file path, delegate to parent
48
+ if @options[:file_path].is_a?(String)
49
+ super
50
+ else
51
+ # Use IO object directly
52
+ content = prepare_file_content(serialized_message)
53
+ @file_handle.write(content)
54
+ @file_handle.flush if @options[:auto_flush]
55
+ end
24
56
  end
25
57
 
26
- def loopback?
27
- @options[:loopback]
58
+ # Override the file content preparation to use custom formatting
59
+ def prepare_file_content(serialized_message)
60
+ format_message(@current_message_class, serialized_message)
28
61
  end
29
62
 
30
- # Publish message to STDOUT (single-tier serialization)
31
- def do_publish(message_class, serialized_message)
32
- logger.debug { "[SmartMessage::StdoutTransport] do_publish called" }
33
- logger.debug { "[SmartMessage::StdoutTransport] message_class: #{message_class}" }
34
-
35
- @output.puts format_message(message_class, serialized_message)
36
- @output.flush
37
-
38
- # If loopback is enabled, route the message back through the dispatcher
39
- if loopback?
40
- logger.debug { "[SmartMessage::StdoutTransport] Loopback enabled, calling receive" }
41
- receive(message_class, serialized_message)
42
- end
43
- rescue => e
44
- logger.error { "[SmartMessage] Error in stdout transport do_publish: #{e.class.name} - #{e.message}" }
45
- raise
63
+ # Override subscribe methods to log warnings since this is a publish-only transport
64
+ def subscribe(message_class, process_method, filter_options = {})
65
+ logger.warn { "[SmartMessage::StdoutTransport] Subscription attempt ignored - STDOUT transport is publish-only (message_class: #{message_class}, process_method: #{process_method})" }
46
66
  end
47
67
 
48
- def connected?
49
- !@output.closed?
68
+ def unsubscribe(message_class, process_method)
69
+ logger.warn { "[SmartMessage::StdoutTransport] Unsubscribe attempt ignored - STDOUT transport is publish-only (message_class: #{message_class}, process_method: #{process_method})" }
50
70
  end
51
71
 
52
- def disconnect
53
- @output.close if @output.respond_to?(:close) && @output != $stdout && @output != $stderr
72
+ def unsubscribe!(message_class)
73
+ logger.warn { "[SmartMessage::StdoutTransport] Unsubscribe all attempt ignored - STDOUT transport is publish-only (message_class: #{message_class})" }
54
74
  end
55
75
 
56
76
  private
57
77
 
58
78
  def format_message(message_class, serialized_message)
59
- <<~MESSAGE
79
+ if @options[:format] == :json
80
+ # Output as JSON for machine parsing
81
+ {
82
+ transport: 'stdout',
83
+ message_class: message_class,
84
+ serialized_message: serialized_message,
85
+ timestamp: Time.now.iso8601
86
+ }.to_json + "\n"
87
+ else
88
+ # Pretty format for human reading
89
+ <<~MESSAGE
60
90
 
61
- ===================================================
62
- == SmartMessage Published via STDOUT Transport
63
- == Single-Tier Serialization:
64
- == Message Class: #{message_class}
65
- == Serialized Message: #{serialized_message}
66
- ===================================================
91
+ ===================================================
92
+ == SmartMessage Published via STDOUT Transport
93
+ == Message Class: #{message_class}
94
+ == Serializer: #{@serializer.class.name}
95
+ == Serialized Message:
96
+ #{serialized_message}
97
+ ===================================================
67
98
 
68
- MESSAGE
99
+ MESSAGE
100
+ end
69
101
  end
70
102
  end
71
103
  end
@@ -0,0 +1,88 @@
1
+ # lib/smart_message/transport/stdout_transport.rb
2
+ # encoding: utf-8
3
+ # frozen_string_literal: true
4
+
5
+ module SmartMessage
6
+ module Transport
7
+ # STDOUT transport for testing and development
8
+ # This is a publish-only transport that outputs messages to STDOUT
9
+ class StdoutTransport < Base
10
+ def default_options
11
+ {
12
+ output: $stdout,
13
+ format: :pretty # :pretty or :json
14
+ }
15
+ end
16
+
17
+ # Default to JSON for readability in STDOUT
18
+ def default_serializer
19
+ SmartMessage::Serializer::Json.new
20
+ end
21
+
22
+ def configure
23
+ @output = @options[:output].is_a?(String) ? File.open(@options[:output], 'w') : @options[:output]
24
+ end
25
+
26
+
27
+ # Publish message to STDOUT
28
+ def do_publish(message_class, serialized_message)
29
+ logger.debug { "[SmartMessage::StdoutTransport] do_publish called" }
30
+ logger.debug { "[SmartMessage::StdoutTransport] message_class: #{message_class}" }
31
+
32
+ @output.puts format_message(message_class, serialized_message)
33
+ @output.flush
34
+ rescue => e
35
+ logger.error { "[SmartMessage] Error in stdout transport do_publish: #{e.class.name} - #{e.message}" }
36
+ raise
37
+ end
38
+
39
+ def connected?
40
+ !@output.closed?
41
+ end
42
+
43
+ def disconnect
44
+ @output.close if @output.respond_to?(:close) && @output != $stdout && @output != $stderr
45
+ end
46
+
47
+ # Override subscribe methods to log warnings since this is a publish-only transport
48
+ def subscribe(message_class, process_method, filter_options = {})
49
+ logger.warn { "[SmartMessage::StdoutTransport] Subscription attempt ignored - STDOUT transport is publish-only (message_class: #{message_class}, process_method: #{process_method})" }
50
+ end
51
+
52
+ def unsubscribe(message_class, process_method)
53
+ logger.warn { "[SmartMessage::StdoutTransport] Unsubscribe attempt ignored - STDOUT transport is publish-only (message_class: #{message_class}, process_method: #{process_method})" }
54
+ end
55
+
56
+ def unsubscribe!(message_class)
57
+ logger.warn { "[SmartMessage::StdoutTransport] Unsubscribe all attempt ignored - STDOUT transport is publish-only (message_class: #{message_class})" }
58
+ end
59
+
60
+ private
61
+
62
+ def format_message(message_class, serialized_message)
63
+ if @options[:format] == :json
64
+ # Output as JSON for machine parsing
65
+ {
66
+ transport: 'stdout',
67
+ message_class: message_class,
68
+ serialized_message: serialized_message,
69
+ timestamp: Time.now.iso8601
70
+ }.to_json
71
+ else
72
+ # Pretty format for human reading
73
+ <<~MESSAGE
74
+
75
+ ===================================================
76
+ == SmartMessage Published via STDOUT Transport
77
+ == Message Class: #{message_class}
78
+ == Serializer: #{@serializer.class.name}
79
+ == Serialized Message:
80
+ #{serialized_message}
81
+ ===================================================
82
+
83
+ MESSAGE
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -7,7 +7,6 @@ require_relative 'transport/registry'
7
7
  require_relative 'transport/stdout_transport'
8
8
  require_relative 'transport/memory_transport'
9
9
  require_relative 'transport/redis_transport'
10
- require_relative 'transport/redis_queue_transport'
11
10
 
12
11
  module SmartMessage
13
12
  module Transport
@@ -3,5 +3,5 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  module SmartMessage
6
- VERSION = '0.0.12'
6
+ VERSION = '0.0.16'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
@@ -311,9 +311,6 @@ files:
311
311
  - docs/development/troubleshooting.md
312
312
  - docs/getting-started/examples.md
313
313
  - docs/getting-started/quick-start.md
314
- - docs/guides/redis-queue-getting-started.md
315
- - docs/guides/redis-queue-patterns.md
316
- - docs/guides/redis-queue-production.md
317
314
  - docs/index.md
318
315
  - docs/reference/dead-letter-queue.md
319
316
  - docs/reference/logging.md
@@ -322,8 +319,7 @@ files:
322
319
  - docs/reference/serializers.md
323
320
  - docs/reference/transports.md
324
321
  - docs/transports/memory-transport.md
325
- - docs/transports/redis-enhanced-transport.md
326
- - docs/transports/redis-queue-transport.md
322
+ - docs/transports/multi-transport.md
327
323
  - docs/transports/redis-transport-comparison.md
328
324
  - docs/transports/redis-transport.md
329
325
  - examples/.gitignore
@@ -360,12 +356,19 @@ files:
360
356
  - examples/city_scenario/start_demo.sh
361
357
  - examples/city_scenario/stop_demo.sh
362
358
  - examples/city_scenario/visitor.rb
359
+ - examples/file/00_run_all_file_demos.rb
360
+ - examples/file/01_basic_file_transport_demo.rb
361
+ - examples/file/02_fifo_transport_demo.rb
362
+ - examples/file/03_file_watching_demo.rb
363
+ - examples/file/04_multi_transport_file_demo.rb
364
+ - examples/file/README.md
365
+ - examples/memory/00_run_all_demos.rb
363
366
  - examples/memory/01_message_deduplication_demo.rb
364
367
  - examples/memory/02_dead_letter_queue_demo.rb
365
368
  - examples/memory/03_point_to_point_orders.rb
366
369
  - examples/memory/04_publish_subscribe_events.rb
367
370
  - examples/memory/05_many_to_many_chat.rb
368
- - examples/memory/06_pretty_print_demo.rb
371
+ - examples/memory/06_stdout_publish_only.rb
369
372
  - examples/memory/07_proc_handlers_demo.rb
370
373
  - examples/memory/08_custom_logger_demo.rb
371
374
  - examples/memory/09_error_handling_demo.rb
@@ -375,10 +378,14 @@ files:
375
378
  - examples/memory/13_header_block_configuration.rb
376
379
  - examples/memory/14_global_configuration_demo.rb
377
380
  - examples/memory/15_logger_demo.rb
381
+ - examples/memory/16_pretty_print_demo.rb
378
382
  - examples/memory/README.md
383
+ - examples/memory/log/demo_app.log.1
384
+ - examples/memory/log/demo_app.log.2
379
385
  - examples/memory/memory_transport_architecture.svg
380
386
  - examples/memory/point_to_point_pattern.svg
381
387
  - examples/memory/publish_subscribe_pattern.svg
388
+ - examples/multi_transport_example.rb
382
389
  - examples/performance_metrics/benchmark_results_ractor_20250818_205603.json
383
390
  - examples/performance_metrics/benchmark_results_ractor_20250818_205831.json
384
391
  - examples/performance_metrics/benchmark_results_test_20250818_204942.json
@@ -399,32 +406,9 @@ files:
399
406
  - examples/redis/redis_transport_architecture.svg
400
407
  - examples/redis/smart_home_iot_dataflow.md
401
408
  - examples/redis/smart_home_system_architecture.svg
402
- - examples/redis_enhanced/README.md
403
- - examples/redis_enhanced/enhanced_01_basic_patterns.rb
404
- - examples/redis_enhanced/enhanced_02_fluent_api.rb
405
- - examples/redis_enhanced/enhanced_03_dual_publishing.rb
406
- - examples/redis_enhanced/enhanced_04_advanced_routing.rb
407
- - examples/redis_queue/01_basic_messaging.rb
408
- - examples/redis_queue/01_comprehensive_examples.rb
409
- - examples/redis_queue/02_pattern_routing.rb
410
- - examples/redis_queue/03_fluent_api.rb
411
- - examples/redis_queue/04_load_balancing.rb
412
- - examples/redis_queue/05_microservices.rb
413
- - examples/redis_queue/06_emergency_alerts.rb
414
- - examples/redis_queue/07_queue_management.rb
415
- - examples/redis_queue/README.md
416
- - examples/redis_queue/enhanced_01_basic_patterns.rb
417
- - examples/redis_queue/enhanced_02_fluent_api.rb
418
- - examples/redis_queue/enhanced_03_dual_publishing.rb
419
- - examples/redis_queue/enhanced_04_advanced_routing.rb
420
- - examples/redis_queue/redis_queue_architecture.svg
421
- - ideas/README.md
422
- - ideas/agents.md
423
- - ideas/database_transport.md
424
- - ideas/improvement.md
425
- - ideas/meshage.md
426
- - ideas/message_discovery.md
427
- - ideas/message_schema.md
409
+ - examples/utilities/box_it.rb
410
+ - examples/utilities/doing.rb
411
+ - examples/utilities/temp.md
428
412
  - lib/simple_stats.rb
429
413
  - lib/smart_message.rb
430
414
  - lib/smart_message/.idea/.gitignore
@@ -461,17 +445,21 @@ files:
461
445
  - lib/smart_message/serializer/json.rb
462
446
  - lib/smart_message/subscription.rb
463
447
  - lib/smart_message/transport.rb
448
+ - lib/smart_message/transport/async_publish_queue.rb
464
449
  - lib/smart_message/transport/base.rb
450
+ - lib/smart_message/transport/fifo_operations.rb
451
+ - lib/smart_message/transport/file_operations.rb
452
+ - lib/smart_message/transport/file_transport.rb
453
+ - lib/smart_message/transport/file_watching.rb
465
454
  - lib/smart_message/transport/memory_transport.rb
466
- - lib/smart_message/transport/redis_enhanced_transport.rb
467
- - lib/smart_message/transport/redis_queue_transport.rb
455
+ - lib/smart_message/transport/partitioned_files.rb
468
456
  - lib/smart_message/transport/redis_transport.rb
469
457
  - lib/smart_message/transport/registry.rb
470
458
  - lib/smart_message/transport/stdout_transport.rb
459
+ - lib/smart_message/transport/stdout_transport.rb.backup
471
460
  - lib/smart_message/utilities.rb
472
461
  - lib/smart_message/version.rb
473
462
  - lib/smart_message/versioning.rb
474
- - lib/smart_message/wrapper.rb.bak
475
463
  - mkdocs.yml
476
464
  - p2p_plan.md
477
465
  - p2p_roadmap.md
@@ -499,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
499
487
  - !ruby/object:Gem::Version
500
488
  version: '0'
501
489
  requirements: []
502
- rubygems_version: 3.7.1
490
+ rubygems_version: 3.7.2
503
491
  specification_version: 4
504
492
  summary: An abstraction to protect message content from the backend delivery transport.
505
493
  test_files: []