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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0f06621d7e381b6069aba0fad1c329b941349e95488bdf5d8d39fd66e1d0fd2
|
4
|
+
data.tar.gz: d1ef64216d07f3e6005db87194590984004bf68f923c09bec93aadb889909cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f06e42c967e586521659b24e132001a64e51d64541214b06c7d5fa7bf6bfc48782a13bec11ace183ae50ff93b3840a5344ea2c59f3b44f0227fe8162b5452c44
|
7
|
+
data.tar.gz: bd2b874f6574600002a5b1cf845ca37076aef74f53fde34b7bae183af5c8978c5dd7c7fdb4d9f442014d7fb146371655e4f3092216e285fc7b0f5fba65dd254f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,126 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.0.16] 2025-09-10
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- **FileTransport Demo Suite**: Comprehensive demonstration programs for FileTransport functionality
|
14
|
+
- **Basic FileTransport Demo** (`examples/file/01_basic_file_transport_demo.rb`): Complete demonstration of core FileTransport features including different output formats (JSON, YAML, raw), append vs overwrite modes, custom serialization, and file rotation examples
|
15
|
+
- **FIFO Transport Demo** (`examples/file/02_fifo_transport_demo.rb`): FIFO (named pipe) demonstrations covering FIFO creation, properties, and concepts with educational content about inter-process communication
|
16
|
+
- **File Watching Demo** (`examples/file/03_file_watching_demo.rb`): File monitoring and change detection examples with polling-based file watching
|
17
|
+
- **Multi-Transport File Demo** (`examples/file/04_multi_transport_file_demo.rb`): Advanced patterns including fan-out to multiple files, conditional routing, multi-transport combinations, archival strategies, and performance monitoring
|
18
|
+
- **Interactive Demo Runner** (`examples/file/00_run_all_file_demos.rb`): Menu-driven demo launcher with comprehensive error handling and user-friendly navigation
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
- **Demo Configuration Syntax**: Fixed incorrect `.configure` method usage throughout FileTransport demos
|
22
|
+
- **Issue**: Demos were using non-existent `MessageClass.configure` method causing "undefined method 'configure'" errors
|
23
|
+
- **Solution**: Updated all configuration calls to use `MessageClass.class_eval { transport transport_instance }` pattern consistent with working examples
|
24
|
+
- **Files Updated**: All FileTransport demo files now use correct transport configuration syntax
|
25
|
+
- **Message Instantiation Arguments**: Fixed keyword argument errors in message creation
|
26
|
+
- **Issue**: Hash variables being passed to `MessageClass.new(hash_var)` instead of using keyword argument expansion
|
27
|
+
- **Solution**: Updated all message instantiation calls to use `MessageClass.new(**hash_var)` for proper keyword argument passing
|
28
|
+
- **Impact**: Resolves "wrong number of arguments (given 1, expected 0)" errors throughout demo suite
|
29
|
+
- **Method Name Consistency**: Updated all demo files to use correct `publish` method instead of deprecated `send`
|
30
|
+
- **Issue**: Some demos were using `.send` method which is not the correct SmartMessage publishing method
|
31
|
+
- **Solution**: Replaced all instances of `.send` with `.publish` across FileTransport demos
|
32
|
+
- **Files Affected**: 02_fifo_transport_demo.rb, 04_multi_transport_file_demo.rb
|
33
|
+
- **Missing `from` Property Declarations**: Added required `from` declarations to all message classes
|
34
|
+
- **Issue**: Message classes missing required `from` property causing "The property 'from' From entity ID is required" errors
|
35
|
+
- **Solution**: Added `from 'demo_source'` declarations to all message class definitions including dynamically created classes
|
36
|
+
- **Impact**: Ensures proper message routing and header initialization
|
37
|
+
- **FIFO Blocking Issues**: Resolved program hanging when writing to FIFOs without concurrent readers
|
38
|
+
- **Issue**: FIFO operations block indefinitely when no reader process is available
|
39
|
+
- **Solution**: Simplified FIFO examples to demonstrate FIFO concepts and properties without blocking operations, replaced complex multi-process examples with educational demonstrations
|
40
|
+
- **Result**: Demos now complete successfully without hanging while still teaching FIFO fundamentals
|
41
|
+
- **Variable Scope Issues**: Fixed transport variable accessibility problems in custom routing logic
|
42
|
+
- **Issue**: Complex custom routing classes couldn't access transport variables from outer scope
|
43
|
+
- **Solution**: Simplified conditional routing examples to use separate message classes for different severity levels instead of dynamic transport switching
|
44
|
+
- **Benefit**: Cleaner, more maintainable code that demonstrates routing concepts without scope complications
|
45
|
+
|
46
|
+
### Enhanced
|
47
|
+
- **Demo Educational Value**: Improved all FileTransport demos with comprehensive documentation and error handling
|
48
|
+
- **Documentation**: Added detailed comments explaining FileTransport concepts, FIFO characteristics, and usage patterns
|
49
|
+
- **Error Handling**: Enhanced error reporting and graceful degradation in all demo scenarios
|
50
|
+
- **User Experience**: Simplified complex examples to focus on core functionality while maintaining educational value
|
51
|
+
- **Output Clarity**: Improved console output formatting and messaging for better understanding of demo operations
|
52
|
+
|
53
|
+
### Documentation
|
54
|
+
- **FileTransport Demo README**: Comprehensive documentation for all FileTransport demonstration programs
|
55
|
+
- **Usage Instructions**: Step-by-step guide for running individual demos and the interactive demo runner
|
56
|
+
- **Concept Explanations**: Detailed explanations of FileTransport features, FIFO operations, and advanced patterns
|
57
|
+
- **Troubleshooting**: Common issues and solutions for FileTransport usage
|
58
|
+
- **Example Outputs**: Sample console outputs showing expected demo results
|
59
|
+
|
60
|
+
## [0.0.15] 2025-09-10
|
61
|
+
|
62
|
+
### Added
|
63
|
+
- **Multi-Transport Publishing**: Messages can now be configured to publish to multiple transports simultaneously
|
64
|
+
- **Core Feature**: Configure messages with an array of transports using `transport [transport1, transport2, transport3]` syntax
|
65
|
+
- **Resilient Publishing**: Publishing succeeds if ANY configured transport works; only fails if ALL transports fail
|
66
|
+
- **Error Handling**: Individual transport failures are logged but don't prevent publishing to remaining transports
|
67
|
+
- **Backward Compatibility**: Single transport configuration continues to work unchanged (`transport single_transport`)
|
68
|
+
- **Utility Methods**: Added `transports()`, `single_transport?()`, and `multiple_transports?()` for transport introspection
|
69
|
+
- **Use Cases**: Supports redundancy, integration, migration, and fan-out messaging patterns
|
70
|
+
|
71
|
+
### Enhanced
|
72
|
+
- **Transport Configuration API**: Extended transport configuration methods to handle both single transports and transport arrays
|
73
|
+
- **Plugins Module**: Updated `transport()` method in `lib/smart_message/plugins.rb` to accept arrays while maintaining backward compatibility
|
74
|
+
- **Internal Storage**: Transport arrays stored internally but `transport()` getter returns first transport for existing code compatibility
|
75
|
+
- **Instance Overrides**: Instance-level transport configuration can override class-level multi-transport settings
|
76
|
+
- **Publishing Pipeline**: Enhanced message publishing in `lib/smart_message/messaging.rb` for multi-transport support
|
77
|
+
- **Parallel Publishing**: Iterates through all configured transports and publishes to each
|
78
|
+
- **Comprehensive Logging**: Logs successful and failed transports with detailed error information
|
79
|
+
- **Error Aggregation**: Collects all transport errors and raises `PublishError` only when all transports fail
|
80
|
+
- **Success Tracking**: Continues processing even when individual transports fail
|
81
|
+
|
82
|
+
### Added - Error Handling
|
83
|
+
- **PublishError**: New error class `SmartMessage::Errors::PublishError` for multi-transport failure scenarios
|
84
|
+
- **Condition**: Only raised when ALL configured transports fail to publish
|
85
|
+
- **Error Detail**: Aggregates error messages from all failed transports for comprehensive debugging
|
86
|
+
- **Added to**: `lib/smart_message/errors.rb`
|
87
|
+
|
88
|
+
### Added - Documentation
|
89
|
+
- **Comprehensive Guide**: Created `docs/transports/multi-transport.md` with complete multi-transport documentation
|
90
|
+
- **Real-World Examples**: High-availability, development/production dual publishing, monitoring integration, A/B testing
|
91
|
+
- **Best Practices**: Performance considerations, environment-specific configuration, health monitoring
|
92
|
+
- **Troubleshooting**: Common issues, debugging techniques, and solutions
|
93
|
+
- **Integration Updates**: Updated main transport documentation and index to reference multi-transport capability
|
94
|
+
- **Transport Layer**: Added multi-transport section to `docs/reference/transports.md`
|
95
|
+
- **Table of Contents**: Added multi-transport link to main documentation index
|
96
|
+
|
97
|
+
### Added - Testing
|
98
|
+
- **Comprehensive Test Suite**: Created `test/multi_transport_test.rb` with 12 test cases covering all functionality
|
99
|
+
- **Backward Compatibility**: Verified single transport behavior remains unchanged
|
100
|
+
- **Multi-Transport Scenarios**: Tests for successful publishing, partial failures, complete failures
|
101
|
+
- **Configuration Testing**: Class vs instance configuration, transport introspection, method chaining
|
102
|
+
- **Mock Transports**: Added `FailingTransport` and `CountingTransport` for controlled testing
|
103
|
+
- **Integration Tests**: Real transport combinations (Memory + STDOUT)
|
104
|
+
|
105
|
+
### Added - Examples
|
106
|
+
- **README Integration**: Added multi-transport example to main README.md with practical use case
|
107
|
+
- **Features Section**: Added multi-transport publishing bullet point to feature list
|
108
|
+
- **Transport Implementations**: Complete section with `CriticalOrderMessage` example showing 3 transports
|
109
|
+
- **Key Benefits**: Highlighted redundancy, integration, migration, and resilience benefits
|
110
|
+
- **Example File**: Created `examples/multi_transport_example.rb` demonstrating all multi-transport functionality
|
111
|
+
- **Usage Patterns**: Single transport (backward compatibility), multiple transports, instance overrides
|
112
|
+
- **Error Scenarios**: Partial transport failure resilience and complete failure handling
|
113
|
+
- **Utility Demonstrations**: Transport counting, type checking, and configuration inspection
|
114
|
+
|
115
|
+
## [0.0.14] 2025-09-10
|
116
|
+
|
117
|
+
### Fixed
|
118
|
+
- **Configuration Architecture**: Fixed `SmartMessage::Serializer.default` method to properly reflect transport-owned serialization architecture
|
119
|
+
- **Issue**: `SmartMessage::Serializer.default` was trying to access a non-existent `default_serializer` method on global configuration
|
120
|
+
- **Root Cause**: Serialization belongs to transports, not global configuration, but the method was attempting to check global config first
|
121
|
+
- **Solution**: Updated method to return framework default (`SmartMessage::Serializer::Json`) directly without depending on global configuration
|
122
|
+
- **Architecture Clarification**: Each transport owns and configures its own serializer (line 19 in transport/base.rb: `@serializer = options[:serializer] || default_serializer`)
|
123
|
+
- **Demo Fix**: Updated `examples/memory/14_global_configuration_demo.rb` to remove incorrect `config.serializer =` attempts and added architecture comments
|
124
|
+
- **Test Method Signatures**: Completed wrapper-to-message architecture transition by fixing remaining method signature issues
|
125
|
+
- **dispatcher_test.rb**: Changed `processer_one` and `processer_two` from instance methods to class methods (`def self.`)
|
126
|
+
- **Message Format**: Updated methods to use flat message structure (`message._sm_header.message_class` and `message.to_json`) instead of old two-tier format (`message_header, encoded_message = message`)
|
127
|
+
- **subscribe_test.rb**: Fixed `business_logic` method to be a class method (`def self.business_logic`) to match subscription call pattern
|
128
|
+
- **Result**: All tests now pass (`176 runs, 578 assertions, 0 failures, 0 errors, 1 skips`) completing the architectural transition
|
129
|
+
|
10
130
|
## [0.0.13] 2025-09-10
|
11
131
|
|
12
132
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_message (0.0.
|
4
|
+
smart_message (0.0.16)
|
5
5
|
activesupport
|
6
6
|
async
|
7
7
|
async-redis
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
json (2.13.2)
|
75
75
|
logger (1.7.0)
|
76
76
|
lumberjack (1.4.1)
|
77
|
-
metrics (0.
|
77
|
+
metrics (0.15.0)
|
78
78
|
minitest (5.25.5)
|
79
79
|
minitest-power_assert (0.3.1)
|
80
80
|
minitest
|
@@ -85,7 +85,7 @@ GEM
|
|
85
85
|
rake (13.3.0)
|
86
86
|
redis (5.4.1)
|
87
87
|
redis-client (>= 0.22.0)
|
88
|
-
redis-client (0.25.
|
88
|
+
redis-client (0.25.3)
|
89
89
|
connection_pool
|
90
90
|
securerandom (0.4.1)
|
91
91
|
shoulda (4.0.0)
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ Think of SmartMessage as ActiveRecord for messaging - just as ActiveRecord frees
|
|
23
23
|
## Features
|
24
24
|
|
25
25
|
- **Transport Abstraction**: Plugin architecture supporting multiple message transports (Redis, RabbitMQ, Kafka, etc.)
|
26
|
+
- **Multi-Transport Publishing**: Send messages to multiple transports simultaneously for redundancy, integration, and migration scenarios
|
26
27
|
- **🌟 Redis Queue Transport**: Advanced transport with RabbitMQ-style routing patterns, persistent FIFO queues, load balancing, and 10x faster performance than traditional message brokers. Built on Ruby's Async framework for fiber-based concurrency supporting thousands of concurrent subscriptions - [see full documentation](docs/transports/redis-queue.md)
|
27
28
|
- **Serialization Flexibility**: Pluggable serialization formats (JSON, MessagePack, etc.)
|
28
29
|
- **Entity-to-Entity Addressing**: Built-in FROM/TO/REPLY_TO addressing for point-to-point and broadcast messaging patterns
|
@@ -36,7 +37,7 @@ Think of SmartMessage as ActiveRecord for messaging - just as ActiveRecord frees
|
|
36
37
|
- **Advanced Logging System**: Comprehensive logging with colorized console output, JSON structured logging, and file rolling
|
37
38
|
- **Built-in Statistics**: Message processing metrics and monitoring
|
38
39
|
- **Message Deduplication**: Handler-scoped deduplication queues (DDQ) with memory or Redis storage for preventing duplicate message processing
|
39
|
-
- **Development Tools**: STDOUT and in-memory
|
40
|
+
- **Development Tools**: STDOUT transport for publish-only scenarios and in-memory transport for testing with local processing
|
40
41
|
- **Production Ready**: Redis transport with automatic reconnection and error handling
|
41
42
|
- **Dead Letter Queue**: File-based DLQ with JSON Lines format for failed message capture and replay
|
42
43
|
- **Circuit Breaker Integration**: Production-grade reliability with BreakerMachines for automatic fallback and recovery
|
@@ -131,8 +132,8 @@ class OrderMessage < SmartMessage::Base
|
|
131
132
|
|
132
133
|
# Configure transport and serializer at class level
|
133
134
|
config do
|
134
|
-
# Option 1:
|
135
|
-
transport SmartMessage::Transport.
|
135
|
+
# Option 1: Memory transport for local development with message processing
|
136
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
136
137
|
|
137
138
|
# Option 2: Redis Queue for production (10x faster than RabbitMQ!)
|
138
139
|
# transport SmartMessage::Transport.create(:redis_queue,
|
@@ -196,24 +197,19 @@ OrderMessage.subscribe
|
|
196
197
|
OrderMessage.subscribe("PaymentService.process_order")
|
197
198
|
|
198
199
|
# 3. Block handler (NEW!)
|
199
|
-
OrderMessage.subscribe do |
|
200
|
-
|
201
|
-
order_data = JSON.parse(payload)
|
202
|
-
puts "Quick processing: Order #{order_data['order_id']}"
|
200
|
+
OrderMessage.subscribe do |message|
|
201
|
+
puts "Quick processing: Order #{message.order_id}"
|
203
202
|
end
|
204
203
|
|
205
204
|
# 4. Proc handler (NEW!)
|
206
|
-
order_processor = proc do |
|
207
|
-
|
208
|
-
order_data = JSON.parse(payload)
|
209
|
-
EmailService.send_confirmation(order_data['customer_id'])
|
205
|
+
order_processor = proc do |message|
|
206
|
+
EmailService.send_confirmation(message.customer_id)
|
210
207
|
end
|
211
208
|
OrderMessage.subscribe(order_processor)
|
212
209
|
|
213
210
|
# 5. Lambda handler (NEW!)
|
214
|
-
audit_handler = lambda do |
|
215
|
-
|
216
|
-
AuditLog.record("Order processed at #{header.published_at}")
|
211
|
+
audit_handler = lambda do |message|
|
212
|
+
AuditLog.record("Order processed at #{message._sm_header.published_at}")
|
217
213
|
end
|
218
214
|
OrderMessage.subscribe(audit_handler)
|
219
215
|
```
|
@@ -542,8 +538,8 @@ The foundation class that all messages inherit from. Built on `Hashie::Dash` wit
|
|
542
538
|
#### Transport Layer
|
543
539
|
Pluggable message delivery system with built-in implementations:
|
544
540
|
|
545
|
-
- **StdoutTransport**:
|
546
|
-
- **MemoryTransport**: In-memory queuing for testing
|
541
|
+
- **StdoutTransport**: Publish-only transport for debugging and external integration
|
542
|
+
- **MemoryTransport**: In-memory queuing for testing with local message processing
|
547
543
|
- **RedisTransport**: Redis pub/sub transport for production messaging
|
548
544
|
- **Custom Transports**: Implement `SmartMessage::Transport::Base`
|
549
545
|
|
@@ -586,6 +582,38 @@ This enables gateway patterns where messages can be received from one transport/
|
|
586
582
|
|
587
583
|
## Transport Implementations
|
588
584
|
|
585
|
+
### Multi-Transport Messages
|
586
|
+
|
587
|
+
SmartMessage supports publishing to multiple transports simultaneously for redundancy, integration, and migration scenarios:
|
588
|
+
|
589
|
+
```ruby
|
590
|
+
class CriticalOrderMessage < SmartMessage::Base
|
591
|
+
property :order_id, required: true
|
592
|
+
property :amount, required: true
|
593
|
+
|
594
|
+
# Configure multiple transports - message goes to ALL of them
|
595
|
+
transport [
|
596
|
+
SmartMessage::Transport.create(:redis_queue, url: 'redis://primary:6379'),
|
597
|
+
SmartMessage::Transport.create(:redis, url: 'redis://backup:6379'),
|
598
|
+
SmartMessage::Transport::StdoutTransport.new(format: :json)
|
599
|
+
]
|
600
|
+
end
|
601
|
+
|
602
|
+
# Publishes to Redis Queue, Redis Pub/Sub, and STDOUT simultaneously
|
603
|
+
message = CriticalOrderMessage.new(order_id: "ORD-123", amount: 99.99)
|
604
|
+
message.publish # ✅ Succeeds if ANY transport works
|
605
|
+
|
606
|
+
# Check transport configuration
|
607
|
+
puts message.multiple_transports? # => true
|
608
|
+
puts message.transports.length # => 3
|
609
|
+
```
|
610
|
+
|
611
|
+
**Key Benefits:**
|
612
|
+
- **Redundancy**: Messages reach multiple destinations for reliability
|
613
|
+
- **Integration**: Simultaneously log to STDOUT, send to Redis, and webhook external systems
|
614
|
+
- **Migration**: Gradually transition between transport systems
|
615
|
+
- **Resilient**: Publishing succeeds as long as ANY transport works
|
616
|
+
|
589
617
|
### Redis Queue Transport (Featured) 🌟
|
590
618
|
|
591
619
|
The Redis Queue Transport provides enterprise-grade message routing with exceptional performance:
|
@@ -637,17 +665,35 @@ OrderMessage.new(
|
|
637
665
|
|
638
666
|
📚 **Full Documentation:** [Redis Queue Transport Guide](docs/transports/redis-queue.md) | [Getting Started](docs/guides/redis-queue-getting-started.md) | [Examples](examples/redis_queue/)
|
639
667
|
|
640
|
-
### STDOUT Transport (
|
668
|
+
### STDOUT Transport (Publish-Only)
|
669
|
+
|
670
|
+
The STDOUT transport is designed for publish-only scenarios - perfect for debugging, logging, or integration with external systems.
|
641
671
|
|
642
672
|
```ruby
|
643
|
-
# Basic STDOUT output
|
644
|
-
transport = SmartMessage::Transport.
|
673
|
+
# Basic STDOUT output (publish-only)
|
674
|
+
transport = SmartMessage::Transport::StdoutTransport.new
|
675
|
+
|
676
|
+
# Pretty-printed format for human reading (default)
|
677
|
+
transport = SmartMessage::Transport::StdoutTransport.new(format: :pretty)
|
645
678
|
|
646
|
-
#
|
647
|
-
transport = SmartMessage::Transport.
|
679
|
+
# JSON format for machine processing
|
680
|
+
transport = SmartMessage::Transport::StdoutTransport.new(format: :json)
|
648
681
|
|
649
|
-
# Output to file
|
650
|
-
transport = SmartMessage::Transport.
|
682
|
+
# Output to file instead of STDOUT
|
683
|
+
transport = SmartMessage::Transport::StdoutTransport.new(output: "messages.log")
|
684
|
+
```
|
685
|
+
|
686
|
+
**Key Features:**
|
687
|
+
- **Publish-only**: No message processing or loopback
|
688
|
+
- **Subscription attempts are ignored** with warning logs
|
689
|
+
- **Two formats**: `:pretty` for debugging, `:json` for integration
|
690
|
+
- **Perfect for**: debugging, logging, piping to external tools
|
691
|
+
- **Use cases**: `./app | jq`, `./app | fluentd`, development monitoring
|
692
|
+
|
693
|
+
**For local message processing, use MemoryTransport instead:**
|
694
|
+
```ruby
|
695
|
+
# Use Memory transport if you need local message processing
|
696
|
+
transport = SmartMessage::Transport::MemoryTransport.new
|
651
697
|
```
|
652
698
|
|
653
699
|
### Memory Transport (Testing)
|
@@ -952,8 +998,8 @@ You can also set descriptions within configuration blocks:
|
|
952
998
|
class ConfiguredMessage < SmartMessage::Base
|
953
999
|
config do
|
954
1000
|
description "Set within config block"
|
955
|
-
transport SmartMessage::Transport.
|
956
|
-
serializer SmartMessage::Serializer::
|
1001
|
+
transport SmartMessage::Transport::MemoryTransport.new
|
1002
|
+
serializer SmartMessage::Serializer::Json.new
|
957
1003
|
end
|
958
1004
|
end
|
959
1005
|
```
|
data/docs/index.md
CHANGED
@@ -31,8 +31,10 @@ Think of SmartMessage as ActiveRecord for messaging - just as ActiveRecord frees
|
|
31
31
|
|
32
32
|
### Transports
|
33
33
|
- [Transport Layer](reference/transports.md)
|
34
|
+
- [Multi-Transport Publishing](transports/multi-transport.md)
|
34
35
|
- [Redis Transport](transports/redis-transport.md)
|
35
36
|
- [Redis Transport Comparison](transports/redis-transport-comparison.md)
|
37
|
+
- [Memory Transport](transports/memory-transport.md)
|
36
38
|
|
37
39
|
### Guides
|
38
40
|
- [Examples & Use Cases](getting-started/examples.md)
|
@@ -5,34 +5,57 @@ The transport layer is responsible for moving messages between systems. SmartMes
|
|
5
5
|
## Overview
|
6
6
|
|
7
7
|
Transports handle:
|
8
|
-
- **Publishing**: Sending messages to a destination
|
8
|
+
- **Publishing**: Sending messages to a destination (single or multiple transports)
|
9
9
|
- **Subscribing**: Registering interest in message types
|
10
10
|
- **Routing**: Directing incoming messages to the dispatcher
|
11
11
|
- **Connection Management**: Handling connections to external systems
|
12
12
|
|
13
|
+
## Multi-Transport Publishing
|
14
|
+
|
15
|
+
SmartMessage supports publishing to **multiple transports simultaneously** for redundancy, integration, and migration scenarios. Configure an array of transports to send messages to multiple destinations with a single `publish()` call.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class CriticalMessage < SmartMessage::Base
|
19
|
+
transport [
|
20
|
+
SmartMessage::Transport.create(:redis_queue, url: 'redis://primary:6379'),
|
21
|
+
SmartMessage::Transport.create(:redis, url: 'redis://backup:6379'),
|
22
|
+
SmartMessage::Transport::StdoutTransport.new(format: :json)
|
23
|
+
]
|
24
|
+
end
|
25
|
+
|
26
|
+
message = CriticalMessage.new(data: "important")
|
27
|
+
message.publish # ✅ Publishes to all three transports
|
28
|
+
```
|
29
|
+
|
30
|
+
**📚 See [Multi-Transport Documentation](../transports/multi-transport.md) for comprehensive examples and best practices.**
|
31
|
+
|
13
32
|
## Built-in Transports
|
14
33
|
|
15
34
|
### STDOUT Transport
|
16
35
|
|
17
|
-
|
36
|
+
**Publish-only transport** perfect for debugging, logging, and integration with external systems.
|
18
37
|
|
19
38
|
**Features:**
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
39
|
+
- **Publish-only**: No message processing or loopback capability
|
40
|
+
- Outputs messages to console or file in pretty-print or JSON formats
|
41
|
+
- Subscription attempts are ignored with warning logs
|
42
|
+
- Perfect for piping to external tools and log aggregators
|
23
43
|
- No external dependencies
|
24
44
|
|
25
45
|
**Usage:**
|
26
46
|
|
27
47
|
```ruby
|
28
|
-
# Basic STDOUT output
|
29
|
-
transport = SmartMessage::Transport.
|
48
|
+
# Basic STDOUT output (publish-only)
|
49
|
+
transport = SmartMessage::Transport::StdoutTransport.new
|
30
50
|
|
31
|
-
#
|
32
|
-
transport = SmartMessage::Transport.
|
51
|
+
# Pretty-printed format for human reading (default)
|
52
|
+
transport = SmartMessage::Transport::StdoutTransport.new(format: :pretty)
|
53
|
+
|
54
|
+
# JSON format for machine processing
|
55
|
+
transport = SmartMessage::Transport::StdoutTransport.new(format: :json)
|
33
56
|
|
34
57
|
# Output to file instead of console
|
35
|
-
transport = SmartMessage::Transport.
|
58
|
+
transport = SmartMessage::Transport::StdoutTransport.new(output: "messages.log")
|
36
59
|
|
37
60
|
# Configure in message class
|
38
61
|
class LogMessage < SmartMessage::Base
|
@@ -40,17 +63,19 @@ class LogMessage < SmartMessage::Base
|
|
40
63
|
property :message
|
41
64
|
|
42
65
|
config do
|
43
|
-
transport SmartMessage::Transport.
|
44
|
-
|
45
|
-
|
66
|
+
transport SmartMessage::Transport::StdoutTransport.new(
|
67
|
+
format: :json,
|
68
|
+
output: "app.log"
|
46
69
|
)
|
47
70
|
end
|
48
71
|
end
|
49
72
|
```
|
50
73
|
|
51
74
|
**Options:**
|
52
|
-
- `
|
53
|
-
- `output` (String|IO): Output destination - filename string or IO object (default:
|
75
|
+
- `format` (Symbol): Output format - `:pretty` for debugging, `:json` for integration (default: `:pretty`)
|
76
|
+
- `output` (String|IO): Output destination - filename string or IO object (default: `$stdout`)
|
77
|
+
|
78
|
+
**Important:** For local message processing during development, use **MemoryTransport** instead.
|
54
79
|
|
55
80
|
**Example Output:**
|
56
81
|
```
|
@@ -421,11 +446,11 @@ end
|
|
421
446
|
order = OrderMessage.new(order_id: "123", amount: 99.99)
|
422
447
|
|
423
448
|
order.config do
|
424
|
-
# This instance will use STDOUT instead of memory
|
425
|
-
transport SmartMessage::Transport.
|
449
|
+
# This instance will use STDOUT instead of memory (publish-only)
|
450
|
+
transport SmartMessage::Transport::StdoutTransport.new(format: :json)
|
426
451
|
end
|
427
452
|
|
428
|
-
order.publish # Uses STDOUT transport
|
453
|
+
order.publish # Uses STDOUT transport (publish-only)
|
429
454
|
```
|
430
455
|
|
431
456
|
### Runtime Transport Switching
|
@@ -490,9 +515,9 @@ transport = SmartMessage::Transport.create(:custom,
|
|
490
515
|
Each transport may have specific options:
|
491
516
|
|
492
517
|
```ruby
|
493
|
-
# STDOUT specific
|
494
|
-
SmartMessage::Transport.
|
495
|
-
|
518
|
+
# STDOUT specific (publish-only)
|
519
|
+
SmartMessage::Transport::StdoutTransport.new(
|
520
|
+
format: :json,
|
496
521
|
output: "/var/log/messages.log"
|
497
522
|
)
|
498
523
|
|
@@ -348,7 +348,8 @@ The `examples/memory/` directory contains comprehensive, runnable examples demon
|
|
348
348
|
- **[12_regex_filtering_microservices.rb](https://github.com/MadBomber/smart_message/blob/main/examples/memory/12_regex_filtering_microservices.rb)** - Advanced regex filtering for microservices
|
349
349
|
|
350
350
|
### Visual Demonstrations
|
351
|
-
- **[
|
351
|
+
- **[06_stdout_publish_only.rb](https://github.com/MadBomber/smart_message/blob/main/examples/memory/06_stdout_publish_only.rb)** - STDOUT transport publish-only demonstration with logging and metrics examples
|
352
|
+
- **[16_pretty_print_demo.rb](https://github.com/MadBomber/smart_message/blob/main/examples/memory/16_pretty_print_demo.rb)** - Message inspection and pretty-printing capabilities
|
352
353
|
|
353
354
|
### Running Examples
|
354
355
|
|