smart_message 0.0.7 → 0.0.9
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/.irbrc +24 -0
- data/CHANGELOG.md +143 -0
- data/Gemfile.lock +6 -1
- data/README.md +289 -15
- data/docs/README.md +3 -1
- data/docs/addressing.md +119 -13
- data/docs/architecture.md +68 -0
- data/docs/dead_letter_queue.md +673 -0
- data/docs/dispatcher.md +87 -0
- data/docs/examples.md +59 -1
- data/docs/getting-started.md +8 -1
- data/docs/logging.md +382 -326
- data/docs/message_filtering.md +451 -0
- data/examples/01_point_to_point_orders.rb +54 -53
- data/examples/02_publish_subscribe_events.rb +14 -10
- data/examples/03_many_to_many_chat.rb +16 -8
- data/examples/04_redis_smart_home_iot.rb +20 -10
- data/examples/05_proc_handlers.rb +12 -11
- data/examples/06_custom_logger_example.rb +95 -100
- data/examples/07_error_handling_scenarios.rb +4 -2
- data/examples/08_entity_addressing_basic.rb +18 -6
- data/examples/08_entity_addressing_with_filtering.rb +27 -9
- data/examples/09_dead_letter_queue_demo.rb +559 -0
- data/examples/09_regex_filtering_microservices.rb +407 -0
- data/examples/10_header_block_configuration.rb +263 -0
- data/examples/11_global_configuration_example.rb +219 -0
- data/examples/README.md +102 -0
- data/examples/dead_letters.jsonl +12 -0
- data/examples/performance_metrics/benchmark_results_ractor_20250818_205603.json +135 -0
- data/examples/performance_metrics/benchmark_results_ractor_20250818_205831.json +135 -0
- data/examples/performance_metrics/benchmark_results_test_20250818_204942.json +130 -0
- data/examples/performance_metrics/benchmark_results_threadpool_20250818_204942.json +130 -0
- data/examples/performance_metrics/benchmark_results_threadpool_20250818_204959.json +130 -0
- data/examples/performance_metrics/benchmark_results_threadpool_20250818_205044.json +130 -0
- data/examples/performance_metrics/benchmark_results_threadpool_20250818_205109.json +130 -0
- data/examples/performance_metrics/benchmark_results_threadpool_20250818_205252.json +130 -0
- data/examples/performance_metrics/benchmark_results_unknown_20250819_172852.json +130 -0
- data/examples/performance_metrics/compare_benchmarks.rb +519 -0
- data/examples/performance_metrics/dead_letters.jsonl +3100 -0
- data/examples/performance_metrics/performance_benchmark.rb +344 -0
- data/examples/show_logger.rb +367 -0
- data/examples/show_me.rb +145 -0
- data/examples/temp.txt +94 -0
- data/examples/tmux_chat/bot_agent.rb +4 -2
- data/examples/tmux_chat/human_agent.rb +4 -2
- data/examples/tmux_chat/room_monitor.rb +4 -2
- data/examples/tmux_chat/shared_chat_system.rb +6 -3
- data/lib/smart_message/addressing.rb +259 -0
- data/lib/smart_message/base.rb +121 -599
- data/lib/smart_message/circuit_breaker.rb +23 -6
- data/lib/smart_message/configuration.rb +199 -0
- data/lib/smart_message/dead_letter_queue.rb +361 -0
- data/lib/smart_message/dispatcher.rb +90 -49
- data/lib/smart_message/header.rb +5 -0
- data/lib/smart_message/logger/base.rb +21 -1
- data/lib/smart_message/logger/default.rb +88 -138
- data/lib/smart_message/logger/lumberjack.rb +324 -0
- data/lib/smart_message/logger/null.rb +81 -0
- data/lib/smart_message/logger.rb +17 -9
- data/lib/smart_message/messaging.rb +100 -0
- data/lib/smart_message/plugins.rb +132 -0
- data/lib/smart_message/serializer/base.rb +25 -8
- data/lib/smart_message/serializer/json.rb +5 -4
- data/lib/smart_message/subscription.rb +193 -0
- data/lib/smart_message/transport/base.rb +84 -53
- data/lib/smart_message/transport/memory_transport.rb +7 -5
- data/lib/smart_message/transport/redis_transport.rb +15 -45
- data/lib/smart_message/transport/stdout_transport.rb +18 -8
- data/lib/smart_message/transport.rb +1 -34
- data/lib/smart_message/utilities.rb +142 -0
- data/lib/smart_message/version.rb +1 -1
- data/lib/smart_message/versioning.rb +85 -0
- data/lib/smart_message/wrapper.rb.bak +132 -0
- data/lib/smart_message.rb +74 -27
- data/smart_message.gemspec +3 -0
- metadata +77 -3
- data/lib/smart_message/serializer.rb +0 -10
- data/lib/smart_message/wrapper.rb +0 -43
data/docs/dispatcher.md
CHANGED
@@ -61,6 +61,93 @@ MyMessage.subscribe { |h,p| puts "Quick log" }
|
|
61
61
|
# All handlers will receive the message
|
62
62
|
```
|
63
63
|
|
64
|
+
### Message Filtering (NEW!)
|
65
|
+
|
66
|
+
SmartMessage supports advanced message filtering using exact strings, regular expressions, or arrays for precise message routing:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# Basic string filtering (exact match)
|
70
|
+
MyMessage.subscribe(from: 'payment-service')
|
71
|
+
MyMessage.subscribe(to: 'order-processor')
|
72
|
+
|
73
|
+
# Regular expression filtering
|
74
|
+
MyMessage.subscribe(from: /^payment-.*/) # All payment services
|
75
|
+
MyMessage.subscribe(to: /^(dev|staging)-.*/) # Development environments
|
76
|
+
|
77
|
+
# Array filtering (multiple options)
|
78
|
+
MyMessage.subscribe(from: ['admin', 'system', 'monitoring'])
|
79
|
+
|
80
|
+
# Mixed exact and pattern matching
|
81
|
+
MyMessage.subscribe(from: ['admin', /^system-.*/, 'legacy-service'])
|
82
|
+
|
83
|
+
# Combined filtering
|
84
|
+
MyMessage.subscribe(
|
85
|
+
from: /^admin-.*/,
|
86
|
+
to: ['order-service', /^fulfillment-.*/]
|
87
|
+
)
|
88
|
+
|
89
|
+
# Broadcast + directed filtering
|
90
|
+
MyMessage.subscribe(broadcast: true, to: 'api-service')
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Filter Types
|
94
|
+
|
95
|
+
**String Filters (Exact Match)**
|
96
|
+
```ruby
|
97
|
+
# Subscribe only to messages from specific sender
|
98
|
+
OrderMessage.subscribe(from: 'payment-service')
|
99
|
+
|
100
|
+
# Subscribe only to messages directed to specific recipient
|
101
|
+
OrderMessage.subscribe(to: 'order-processor')
|
102
|
+
```
|
103
|
+
|
104
|
+
**Regular Expression Filters (Pattern Match)**
|
105
|
+
```ruby
|
106
|
+
# Environment-based routing
|
107
|
+
DevService.subscribe(to: /^(dev|staging)-.*/)
|
108
|
+
ProdService.subscribe(to: /^prod-.*/)
|
109
|
+
|
110
|
+
# Service pattern routing
|
111
|
+
PaymentProcessor.subscribe(from: /^payment-.*/)
|
112
|
+
ApiService.subscribe(from: /^(web|mobile|api)-.*/)
|
113
|
+
```
|
114
|
+
|
115
|
+
**Array Filters (Multiple Options)**
|
116
|
+
```ruby
|
117
|
+
# Multiple specific services
|
118
|
+
AdminService.subscribe(from: ['admin', 'system', 'monitoring'])
|
119
|
+
|
120
|
+
# Mixed patterns and exact matches
|
121
|
+
AlertService.subscribe(from: ['admin', /^system-.*/, 'security'])
|
122
|
+
```
|
123
|
+
|
124
|
+
**Combined Filters**
|
125
|
+
```ruby
|
126
|
+
# Complex multi-criteria filtering
|
127
|
+
OrderMessage.subscribe(
|
128
|
+
from: /^(admin|system)-.*/,
|
129
|
+
to: ['order-service', /^fulfillment-.*/]
|
130
|
+
)
|
131
|
+
|
132
|
+
# Admin services to production only
|
133
|
+
AdminMessage.subscribe(from: /^admin-.*/, to: /^prod-.*/)
|
134
|
+
```
|
135
|
+
|
136
|
+
#### Filter Validation
|
137
|
+
|
138
|
+
Filters are validated at subscription time:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
# Valid filters
|
142
|
+
MyMessage.subscribe(from: 'service') # String
|
143
|
+
MyMessage.subscribe(from: /^service-.*/) # Regexp
|
144
|
+
MyMessage.subscribe(from: ['a', /^b-.*/]) # Array of String/Regexp
|
145
|
+
|
146
|
+
# Invalid filters (raise ArgumentError)
|
147
|
+
MyMessage.subscribe(from: 123) # Invalid type
|
148
|
+
MyMessage.subscribe(from: ['valid', 123]) # Invalid array element
|
149
|
+
```
|
150
|
+
|
64
151
|
### Removing Subscriptions
|
65
152
|
|
66
153
|
```ruby
|
data/docs/examples.md
CHANGED
@@ -807,4 +807,62 @@ end
|
|
807
807
|
test_message_processing
|
808
808
|
```
|
809
809
|
|
810
|
-
These examples demonstrate the flexibility and power of SmartMessage for building robust, scalable messaging systems. Each pattern can be adapted to your specific needs and combined with other patterns for more complex workflows.
|
810
|
+
These examples demonstrate the flexibility and power of SmartMessage for building robust, scalable messaging systems. Each pattern can be adapted to your specific needs and combined with other patterns for more complex workflows.
|
811
|
+
|
812
|
+
## Executable Example Programs
|
813
|
+
|
814
|
+
The `examples/` directory contains complete, runnable programs that demonstrate various SmartMessage features:
|
815
|
+
|
816
|
+
### Core Messaging Patterns
|
817
|
+
- **`01_point_to_point_orders.rb`** - Point-to-point order processing with payment integration
|
818
|
+
- **`02_publish_subscribe_events.rb`** - Event broadcasting to multiple services (email, SMS, audit)
|
819
|
+
- **`03_many_to_many_chat.rb`** - Interactive chat system with rooms, bots, and human agents
|
820
|
+
|
821
|
+
### Advanced Features
|
822
|
+
- **`04_redis_smart_home_iot.rb`** - Redis-based IoT sensor monitoring with real-time data flow
|
823
|
+
- **`05_proc_handlers.rb`** - Flexible message handlers (blocks, procs, lambdas, methods)
|
824
|
+
- **`06_custom_logger_example.rb`** - Advanced logging with SmartMessage::Logger::Default
|
825
|
+
- **`07_error_handling_scenarios.rb`** - Comprehensive validation, version mismatch, and error handling
|
826
|
+
- **`08_entity_addressing_basic.rb`** - Basic FROM/TO/REPLY_TO message addressing
|
827
|
+
- **`08_entity_addressing_with_filtering.rb`** - Advanced entity-aware message filtering
|
828
|
+
- **`09_dead_letter_queue_demo.rb`** - Complete Dead Letter Queue system demonstration
|
829
|
+
|
830
|
+
### Interactive Demos
|
831
|
+
- **`tmux_chat/`** - Multi-pane terminal visualization of many-to-many messaging with file-based transport
|
832
|
+
|
833
|
+
### Running Examples
|
834
|
+
|
835
|
+
```bash
|
836
|
+
# Navigate to the SmartMessage directory
|
837
|
+
cd smart_message
|
838
|
+
|
839
|
+
# Run any example directly
|
840
|
+
ruby examples/01_point_to_point_orders.rb
|
841
|
+
ruby examples/09_dead_letter_queue_demo.rb
|
842
|
+
|
843
|
+
# For tmux chat demo
|
844
|
+
cd examples/tmux_chat && ./run_demo.sh
|
845
|
+
```
|
846
|
+
|
847
|
+
Each example is self-contained and includes:
|
848
|
+
- Clear educational comments
|
849
|
+
- Multiple message classes
|
850
|
+
- Complete setup and teardown
|
851
|
+
- Real-world scenarios
|
852
|
+
- Best practices demonstration
|
853
|
+
|
854
|
+
### Example Features Demonstrated
|
855
|
+
|
856
|
+
| Example | Transports | Features | Use Case |
|
857
|
+
|---------|------------|----------|----------|
|
858
|
+
| 01 | STDOUT | Point-to-point, validation | Order processing |
|
859
|
+
| 02 | STDOUT | Pub-sub, multiple handlers | Event broadcasting |
|
860
|
+
| 03 | Memory | Many-to-many, bots | Chat systems |
|
861
|
+
| 04 | Redis | IoT, real-time, addressing | Smart home monitoring |
|
862
|
+
| 05 | Memory | Proc handlers, flexibility | Dynamic message handling |
|
863
|
+
| 06 | STDOUT | Custom logging, lifecycle | Production logging |
|
864
|
+
| 07 | STDOUT | Error handling, validation | Robust message systems |
|
865
|
+
| 08 | STDOUT | Entity addressing, filtering | Microservice communication |
|
866
|
+
| 09 | Memory | DLQ, circuit breakers, replay | Production reliability |
|
867
|
+
|
868
|
+
These examples provide practical, working code that you can use as a starting point for your own SmartMessage implementations.
|
data/docs/getting-started.md
CHANGED
@@ -40,11 +40,18 @@ class WelcomeMessage < SmartMessage::Base
|
|
40
40
|
# Add a description for the message class
|
41
41
|
description "Welcomes new users after successful signup"
|
42
42
|
|
43
|
-
# Configure entity addressing
|
43
|
+
# Configure entity addressing (Method 1: Direct methods)
|
44
44
|
from 'user-service' # Required: identifies sender
|
45
45
|
to 'notification-service' # Optional: specific recipient
|
46
46
|
reply_to 'user-service' # Optional: where responses go
|
47
47
|
|
48
|
+
# Alternative Method 2: Using header block
|
49
|
+
# header do
|
50
|
+
# from 'user-service'
|
51
|
+
# to 'notification-service'
|
52
|
+
# reply_to 'user-service'
|
53
|
+
# end
|
54
|
+
|
48
55
|
# Define message properties
|
49
56
|
property :user_name
|
50
57
|
property :email
|