smart_message 0.0.10 → 0.0.12
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/.github/workflows/deploy-github-pages.yml +38 -0
- data/.gitignore +5 -0
- data/CHANGELOG.md +30 -0
- data/Gemfile.lock +35 -4
- data/README.md +169 -71
- data/Rakefile +29 -4
- data/docs/assets/images/ddq_architecture.svg +130 -0
- data/docs/assets/images/dlq_architecture.svg +115 -0
- data/docs/assets/images/enhanced-dual-publishing.svg +136 -0
- data/docs/assets/images/enhanced-fluent-api.svg +149 -0
- data/docs/assets/images/enhanced-microservices-routing.svg +115 -0
- data/docs/assets/images/enhanced-pattern-matching.svg +107 -0
- data/docs/assets/images/fluent-api-demo.svg +59 -0
- data/docs/assets/images/performance-comparison.svg +161 -0
- data/docs/assets/images/redis-basic-architecture.svg +53 -0
- data/docs/assets/images/redis-enhanced-architecture.svg +88 -0
- data/docs/assets/images/redis-queue-architecture.svg +101 -0
- data/docs/assets/images/smart_message.jpg +0 -0
- data/docs/assets/images/smart_message_walking.jpg +0 -0
- data/docs/assets/images/smartmessage_architecture_overview.svg +173 -0
- data/docs/assets/images/transport-comparison-matrix.svg +171 -0
- data/docs/assets/javascripts/mathjax.js +17 -0
- data/docs/assets/stylesheets/extra.css +51 -0
- data/docs/{addressing.md → core-concepts/addressing.md} +5 -7
- data/docs/{architecture.md → core-concepts/architecture.md} +78 -138
- data/docs/{dispatcher.md → core-concepts/dispatcher.md} +21 -21
- data/docs/{message_filtering.md → core-concepts/message-filtering.md} +2 -3
- data/docs/{message_processing.md → core-concepts/message-processing.md} +17 -17
- data/docs/{troubleshooting.md → development/troubleshooting.md} +7 -7
- data/docs/{examples.md → getting-started/examples.md} +115 -89
- data/docs/{getting-started.md → getting-started/quick-start.md} +47 -18
- data/docs/guides/redis-queue-getting-started.md +697 -0
- data/docs/guides/redis-queue-patterns.md +889 -0
- data/docs/guides/redis-queue-production.md +1091 -0
- data/docs/index.md +64 -0
- data/docs/{dead_letter_queue.md → reference/dead-letter-queue.md} +2 -3
- data/docs/{logging.md → reference/logging.md} +1 -1
- data/docs/{message_deduplication.md → reference/message-deduplication.md} +1 -0
- data/docs/{proc_handlers_summary.md → reference/proc-handlers.md} +7 -6
- data/docs/{serializers.md → reference/serializers.md} +3 -5
- data/docs/{transports.md → reference/transports.md} +133 -11
- data/docs/transports/memory-transport.md +374 -0
- data/docs/transports/redis-enhanced-transport.md +524 -0
- data/docs/transports/redis-queue-transport.md +1304 -0
- data/docs/transports/redis-transport-comparison.md +496 -0
- data/docs/transports/redis-transport.md +509 -0
- data/examples/README.md +98 -5
- data/examples/city_scenario/911_emergency_call_flow.svg +99 -0
- data/examples/city_scenario/README.md +515 -0
- data/examples/city_scenario/ai_visitor_intelligence_flow.svg +108 -0
- data/examples/city_scenario/citizen.rb +195 -0
- data/examples/city_scenario/city_diagram.svg +125 -0
- data/examples/city_scenario/common/health_monitor.rb +80 -0
- data/examples/city_scenario/common/logger.rb +30 -0
- data/examples/city_scenario/emergency_dispatch_center.rb +270 -0
- data/examples/city_scenario/fire_department.rb +446 -0
- data/examples/city_scenario/fire_emergency_flow.svg +95 -0
- data/examples/city_scenario/health_department.rb +100 -0
- data/examples/city_scenario/health_monitoring_system.svg +130 -0
- data/examples/city_scenario/house.rb +244 -0
- data/examples/city_scenario/local_bank.rb +217 -0
- data/examples/city_scenario/messages/emergency_911_message.rb +81 -0
- data/examples/city_scenario/messages/emergency_resolved_message.rb +43 -0
- data/examples/city_scenario/messages/fire_dispatch_message.rb +43 -0
- data/examples/city_scenario/messages/fire_emergency_message.rb +45 -0
- data/examples/city_scenario/messages/health_check_message.rb +22 -0
- data/examples/city_scenario/messages/health_status_message.rb +35 -0
- data/examples/city_scenario/messages/police_dispatch_message.rb +46 -0
- data/examples/city_scenario/messages/silent_alarm_message.rb +38 -0
- data/examples/city_scenario/police_department.rb +316 -0
- data/examples/city_scenario/redis_monitor.rb +129 -0
- data/examples/city_scenario/redis_stats.rb +743 -0
- data/examples/city_scenario/room_for_improvement.md +240 -0
- data/examples/city_scenario/security_emergency_flow.svg +95 -0
- data/examples/city_scenario/service_internal_architecture.svg +154 -0
- data/examples/city_scenario/smart_message_ai_agent.rb +364 -0
- data/examples/city_scenario/start_demo.sh +236 -0
- data/examples/city_scenario/stop_demo.sh +106 -0
- data/examples/city_scenario/visitor.rb +631 -0
- data/examples/{10_message_deduplication.rb → memory/01_message_deduplication_demo.rb} +1 -1
- data/examples/{09_dead_letter_queue_demo.rb → memory/02_dead_letter_queue_demo.rb} +13 -40
- data/examples/{01_point_to_point_orders.rb → memory/03_point_to_point_orders.rb} +1 -1
- data/examples/{02_publish_subscribe_events.rb → memory/04_publish_subscribe_events.rb} +2 -2
- data/examples/{03_many_to_many_chat.rb → memory/05_many_to_many_chat.rb} +4 -4
- data/examples/{show_me.rb → memory/06_pretty_print_demo.rb} +1 -1
- data/examples/{05_proc_handlers.rb → memory/07_proc_handlers_demo.rb} +2 -2
- data/examples/{06_custom_logger_example.rb → memory/08_custom_logger_demo.rb} +17 -14
- data/examples/{07_error_handling_scenarios.rb → memory/09_error_handling_demo.rb} +4 -4
- data/examples/{08_entity_addressing_basic.rb → memory/10_entity_addressing_basic.rb} +8 -8
- data/examples/{08_entity_addressing_with_filtering.rb → memory/11_entity_addressing_with_filtering.rb} +6 -6
- data/examples/{09_regex_filtering_microservices.rb → memory/12_regex_filtering_microservices.rb} +2 -2
- data/examples/{10_header_block_configuration.rb → memory/13_header_block_configuration.rb} +6 -6
- data/examples/{11_global_configuration_example.rb → memory/14_global_configuration_demo.rb} +19 -8
- data/examples/{show_logger.rb → memory/15_logger_demo.rb} +1 -1
- data/examples/memory/README.md +163 -0
- data/examples/memory/memory_transport_architecture.svg +90 -0
- data/examples/memory/point_to_point_pattern.svg +94 -0
- data/examples/memory/publish_subscribe_pattern.svg +125 -0
- data/examples/{04_redis_smart_home_iot.rb → redis/01_smart_home_iot_demo.rb} +5 -5
- data/examples/redis/README.md +230 -0
- data/examples/redis/alert_system_flow.svg +127 -0
- data/examples/redis/dashboard_status_flow.svg +107 -0
- data/examples/redis/device_command_flow.svg +113 -0
- data/examples/redis/redis_transport_architecture.svg +115 -0
- data/examples/{smart_home_iot_dataflow.md → redis/smart_home_iot_dataflow.md} +4 -116
- data/examples/redis/smart_home_system_architecture.svg +133 -0
- data/examples/redis_enhanced/README.md +319 -0
- data/examples/redis_enhanced/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_enhanced/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_enhanced/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_enhanced/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/01_basic_messaging.rb +221 -0
- data/examples/redis_queue/01_comprehensive_examples.rb +508 -0
- data/examples/redis_queue/02_pattern_routing.rb +405 -0
- data/examples/redis_queue/03_fluent_api.rb +422 -0
- data/examples/redis_queue/04_load_balancing.rb +486 -0
- data/examples/redis_queue/05_microservices.rb +735 -0
- data/examples/redis_queue/06_emergency_alerts.rb +777 -0
- data/examples/redis_queue/07_queue_management.rb +587 -0
- data/examples/redis_queue/README.md +366 -0
- data/examples/redis_queue/enhanced_01_basic_patterns.rb +233 -0
- data/examples/redis_queue/enhanced_02_fluent_api.rb +331 -0
- data/examples/redis_queue/enhanced_03_dual_publishing.rb +281 -0
- data/examples/redis_queue/enhanced_04_advanced_routing.rb +419 -0
- data/examples/redis_queue/redis_queue_architecture.svg +148 -0
- data/ideas/README.md +41 -0
- data/ideas/agents.md +1001 -0
- data/ideas/database_transport.md +980 -0
- data/ideas/improvement.md +359 -0
- data/ideas/meshage.md +1788 -0
- data/ideas/message_discovery.md +178 -0
- data/ideas/message_schema.md +1381 -0
- data/lib/smart_message/.idea/.gitignore +8 -0
- data/lib/smart_message/.idea/markdown.xml +6 -0
- data/lib/smart_message/.idea/misc.xml +4 -0
- data/lib/smart_message/.idea/modules.xml +8 -0
- data/lib/smart_message/.idea/smart_message.iml +16 -0
- data/lib/smart_message/.idea/vcs.xml +6 -0
- data/lib/smart_message/addressing.rb +15 -0
- data/lib/smart_message/base.rb +0 -2
- data/lib/smart_message/configuration.rb +1 -1
- data/lib/smart_message/logger.rb +15 -4
- data/lib/smart_message/plugins.rb +5 -2
- data/lib/smart_message/serializer.rb +14 -0
- data/lib/smart_message/transport/redis_enhanced_transport.rb +399 -0
- data/lib/smart_message/transport/redis_queue_transport.rb +555 -0
- data/lib/smart_message/transport/registry.rb +1 -0
- data/lib/smart_message/transport.rb +34 -1
- data/lib/smart_message/version.rb +1 -1
- data/lib/smart_message.rb +5 -52
- data/mkdocs.yml +184 -0
- data/p2p_plan.md +326 -0
- data/p2p_roadmap.md +287 -0
- data/smart_message.gemspec +2 -0
- data/smart_message.svg +51 -0
- metadata +170 -44
- data/docs/README.md +0 -57
- data/examples/dead_letters.jsonl +0 -12
- data/examples/temp.txt +0 -94
- data/examples/tmux_chat/README.md +0 -283
- data/examples/tmux_chat/bot_agent.rb +0 -278
- data/examples/tmux_chat/human_agent.rb +0 -199
- data/examples/tmux_chat/room_monitor.rb +0 -160
- data/examples/tmux_chat/shared_chat_system.rb +0 -328
- data/examples/tmux_chat/start_chat_demo.sh +0 -190
- data/examples/tmux_chat/stop_chat_demo.sh +0 -22
- /data/docs/{properties.md → core-concepts/properties.md} +0 -0
- /data/docs/{ideas_to_think_about.md → development/ideas.md} +0 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
## Message Discovery & Dynamic Class Creation
|
2
|
+
|
3
|
+
### Overview
|
4
|
+
|
5
|
+
SmartMessage can automatically discover and catalog message types across distributed systems, enabling:
|
6
|
+
|
7
|
+
- **Service discovery** - Find available message types from other services
|
8
|
+
- **Dynamic class creation** - Create message classes from stored schemas at runtime
|
9
|
+
- **Cross-service communication** - Connect to new services without code changes
|
10
|
+
- **API documentation** - Generate docs from actual schemas in use
|
11
|
+
|
12
|
+
### Service Discovery Implementation
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
module SmartMessage
|
16
|
+
class SchemaRegistry
|
17
|
+
# Service discovery: find available message types
|
18
|
+
def discover_message_classes(environment: nil, service: nil)
|
19
|
+
filters = ["status = 'active'"]
|
20
|
+
params = []
|
21
|
+
|
22
|
+
if environment
|
23
|
+
filters << "deployment_environment = $#{params.length + 1}"
|
24
|
+
params << environment
|
25
|
+
end
|
26
|
+
|
27
|
+
if service
|
28
|
+
filters << "registered_by = $#{params.length + 1}"
|
29
|
+
params << service
|
30
|
+
end
|
31
|
+
|
32
|
+
connection_pool.with do |conn|
|
33
|
+
conn.execute(<<~SQL, params)
|
34
|
+
SELECT DISTINCT
|
35
|
+
class_name,
|
36
|
+
MAX(class_version) as latest_version,
|
37
|
+
MAX(class_description) as description,
|
38
|
+
COUNT(*) as version_count,
|
39
|
+
MAX(registered_at) as last_updated
|
40
|
+
FROM smart_message_schemas
|
41
|
+
WHERE #{filters.join(' AND ')}
|
42
|
+
GROUP BY class_name
|
43
|
+
ORDER BY class_name
|
44
|
+
SQL
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
### Dynamic Class Creation
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
module SmartMessage
|
55
|
+
class SchemaRegistry
|
56
|
+
# Dynamic class creation from stored schema
|
57
|
+
def create_class_from_schema(class_name, version = :latest, namespace = Object)
|
58
|
+
schema = fetch_schema(class_name, version)
|
59
|
+
raise ArgumentError, "Schema not found: #{class_name} v#{version}" unless schema
|
60
|
+
|
61
|
+
# Extract class name without namespace
|
62
|
+
simple_class_name = class_name.split('::').last
|
63
|
+
|
64
|
+
# Create dynamic class
|
65
|
+
dynamic_class = Class.new(SmartMessage::Base) do
|
66
|
+
# Set metadata
|
67
|
+
description schema['class_description']
|
68
|
+
version schema['class_version']
|
69
|
+
|
70
|
+
# Add properties with full validation
|
71
|
+
schema['properties_schema'].each do |prop|
|
72
|
+
property_options = build_property_options(prop)
|
73
|
+
property prop['name'].to_sym, **property_options
|
74
|
+
end
|
75
|
+
|
76
|
+
# Apply validations
|
77
|
+
apply_validation_rules(schema['validations_schema']) if schema['validations_schema']
|
78
|
+
|
79
|
+
# Apply configuration
|
80
|
+
apply_configuration(schema['configuration_schema']) if schema['configuration_schema']
|
81
|
+
|
82
|
+
# Mark as dynamically created
|
83
|
+
define_singleton_method(:dynamically_created?) { true }
|
84
|
+
define_singleton_method(:source_schema) { schema }
|
85
|
+
end
|
86
|
+
|
87
|
+
# Set constant
|
88
|
+
namespace.const_set(simple_class_name, dynamic_class)
|
89
|
+
dynamic_class
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def fetch_schema(class_name, version)
|
95
|
+
version_clause = version == :latest ?
|
96
|
+
"ORDER BY class_version DESC LIMIT 1" :
|
97
|
+
"AND class_version = #{version.to_i}"
|
98
|
+
|
99
|
+
connection_pool.with do |conn|
|
100
|
+
conn.execute(<<~SQL, [class_name]).first
|
101
|
+
SELECT * FROM smart_message_schemas
|
102
|
+
WHERE class_name = $1 AND status = 'active'
|
103
|
+
#{version_clause}
|
104
|
+
SQL
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
### Usage Examples
|
112
|
+
|
113
|
+
#### Service Discovery
|
114
|
+
```ruby
|
115
|
+
# Discover all available message types in production
|
116
|
+
available_messages = SmartMessage::SchemaRegistry.discover_message_classes(
|
117
|
+
environment: 'production'
|
118
|
+
)
|
119
|
+
|
120
|
+
available_messages.each do |msg|
|
121
|
+
puts "#{msg['class_name']} v#{msg['latest_version']} - #{msg['description']}"
|
122
|
+
end
|
123
|
+
|
124
|
+
# Discover messages from a specific service
|
125
|
+
partner_messages = SmartMessage::SchemaRegistry.discover_message_classes(
|
126
|
+
service: 'payment-service'
|
127
|
+
)
|
128
|
+
```
|
129
|
+
|
130
|
+
#### Dynamic Class Creation
|
131
|
+
```ruby
|
132
|
+
# Create a message class dynamically from another service's schema
|
133
|
+
PaymentMessage = SmartMessage::SchemaRegistry.create_class_from_schema(
|
134
|
+
'PaymentMessage',
|
135
|
+
version: :latest
|
136
|
+
)
|
137
|
+
|
138
|
+
# Use the dynamically created class
|
139
|
+
payment = PaymentMessage.new(
|
140
|
+
amount: 99.99,
|
141
|
+
currency: 'USD',
|
142
|
+
customer_id: 'cust_123'
|
143
|
+
)
|
144
|
+
|
145
|
+
# Check if class was dynamically created
|
146
|
+
payment.class.dynamically_created? # => true
|
147
|
+
payment.class.source_schema # => returns original schema used to create class
|
148
|
+
```
|
149
|
+
|
150
|
+
#### Cross-Service Communication
|
151
|
+
```ruby
|
152
|
+
# Load message schemas from partner service
|
153
|
+
partner_schemas = SmartMessage::SchemaRegistry.discover_message_classes(
|
154
|
+
service: 'partner-payment-service'
|
155
|
+
)
|
156
|
+
|
157
|
+
# Automatically create local classes for their message types
|
158
|
+
partner_schemas.each do |schema_info|
|
159
|
+
SmartMessage::SchemaRegistry.create_class_from_schema(
|
160
|
+
schema_info['class_name'],
|
161
|
+
namespace: PartnerMessages
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Now can subscribe to partner messages
|
166
|
+
PartnerMessages::PaymentCompletedMessage.subscribe do |message|
|
167
|
+
# Handle partner payment notifications
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
### Discovery Benefits
|
172
|
+
|
173
|
+
1. **Automatic Service Discovery**: Find available message types across services without manual documentation
|
174
|
+
2. **Dynamic Integration**: Connect to new services without code changes or deployments
|
175
|
+
3. **API Documentation**: Generate accurate docs from actual schemas in use
|
176
|
+
4. **Validation**: Ensure message compatibility across service boundaries
|
177
|
+
5. **Debugging**: Understand message structure across the entire system
|
178
|
+
6. **Zero-downtime Updates**: Services can discover and adapt to new message types at runtime
|