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,361 @@
1
+ # Transport Selection Guide
2
+
3
+ Choosing the right transport for your SmartMessage application is crucial for performance, reliability, and maintainability. This guide provides comprehensive information about each available transport and decision matrices to help you select the optimal transport configuration.
4
+
5
+ ## Available Transports
6
+
7
+ ### Memory Transport
8
+ **In-memory message storage for development and testing**
9
+
10
+ - **Type**: In-memory queue with optional auto-processing
11
+ - **Best For**: Unit testing, development, rapid prototyping, message inspection
12
+ - **Key Features**:
13
+ - No external dependencies
14
+ - Thread-safe operations
15
+ - Message inspection capabilities
16
+ - Configurable memory limits
17
+ - Fastest performance (~0.01ms latency)
18
+ - **Limitations**: Single-process only, no persistence, memory usage grows with volume
19
+ - **Use Cases**: Unit tests, development debugging, in-memory message queuing
20
+
21
+ ### Redis Transport
22
+ **Production-ready Redis pub/sub for distributed messaging**
23
+
24
+ - **Type**: Redis pub/sub with broadcast delivery
25
+ - **Best For**: Production messaging, microservices communication, real-time applications
26
+ - **Key Features**:
27
+ - Distributed messaging support
28
+ - Automatic reconnection handling
29
+ - High throughput (80K+ messages/second)
30
+ - Low latency (~1ms)
31
+ - Thread-based subscriber model
32
+ - **Limitations**: No message persistence, no pattern matching, all subscribers receive all messages
33
+ - **Use Cases**: Production systems, scalable architectures, service-to-service messaging
34
+
35
+ ### STDOUT Transport
36
+ **Console and file output with multiple formatting options**
37
+
38
+ - **Type**: Output-only transport with formatting capabilities
39
+ - **Best For**: Development debugging, application logging, message tracing, integration testing
40
+ - **Key Features**:
41
+ - Three output formats (`:pretty`, `:jsonl`, `:json`)
42
+ - Console or file output
43
+ - Optional loopback processing
44
+ - Human-readable pretty printing
45
+ - Thread-safe file operations
46
+ - **Limitations**: Not suitable for production messaging, single output destination
47
+ - **Use Cases**: Development debugging, structured logging, message flow tracing
48
+
49
+ ### File Transport
50
+ **Base class for file-based messaging**
51
+
52
+ - **Type**: Abstract base class for file-based transports
53
+ - **Best For**: Custom file-based transport implementations, message archiving
54
+ - **Key Features**:
55
+ - Automatic directory creation
56
+ - Thread-safe file operations
57
+ - Message serialization handling
58
+ - Extensible architecture for custom transports
59
+ - **Limitations**: Rarely used directly, requires custom implementation
60
+ - **Use Cases**: Custom transport development, message persistence, audit trails
61
+
62
+ ### Multi-Transport Publishing
63
+ **Simultaneous publishing to multiple transports**
64
+
65
+ - **Type**: Configuration pattern for publishing to multiple destinations
66
+ - **Best For**: High availability, migration scenarios, monitoring integration, redundancy
67
+ - **Key Features**:
68
+ - Publish to multiple transports with single `publish()` call
69
+ - Resilient to partial failures
70
+ - Sequential processing with error isolation
71
+ - Transport introspection methods
72
+ - **Limitations**: Sequential processing can impact performance, memory usage scales with transport count
73
+ - **Use Cases**: Critical message redundancy, gradual migration, operational monitoring
74
+
75
+ ## Transport Selection Matrix
76
+
77
+ ### By Development Phase
78
+
79
+ | Phase | Primary Transport | Secondary Transport | Use Case |
80
+ |-------|------------------|-------------------|----------|
81
+ | **Unit Testing** | Memory | - | Fast, isolated, inspectable |
82
+ | **Development** | STDOUT (pretty) | Memory (loopback) | Human-readable debugging |
83
+ | **Integration Testing** | STDOUT (jsonl) | Memory | Structured output, verification |
84
+ | **Staging** | Redis | STDOUT (file) | Production-like with logging |
85
+ | **Production** | Redis | Multi-transport | Scalable with redundancy |
86
+
87
+ ### By Use Case
88
+
89
+ | Use Case | Recommended Transport | Configuration | Rationale |
90
+ |----------|----------------------|---------------|-----------|
91
+ | **Unit Tests** | Memory | `auto_process: true` | No dependencies, fast, inspectable |
92
+ | **Development Debugging** | STDOUT | `format: :pretty, loopback: true` | Human-readable with local processing |
93
+ | **Application Logging** | STDOUT | `format: :jsonl, file_path: 'app.log'` | Structured logs for analysis |
94
+ | **Message Tracing** | STDOUT | `format: :json, file_path: '/tmp/trace.log'` | Compact format for debugging |
95
+ | **Production Messaging** | Redis | `url: ENV['REDIS_URL']` | Distributed, reliable, scalable |
96
+ | **Critical Messages** | Multi-transport | `[Redis, STDOUT(file), Redis(backup)]` | Redundancy and audit trail |
97
+ | **Migration Scenarios** | Multi-transport | `[OldTransport, NewTransport]` | Gradual transition |
98
+ | **Development→Production** | Environment-based | Switch based on `Rails.env` | Appropriate for each environment |
99
+
100
+ ### By Architecture Pattern
101
+
102
+ #### Single Application (Monolith)
103
+ ```ruby
104
+ # Development
105
+ transport: SmartMessage::Transport::StdoutTransport.new(format: :pretty)
106
+
107
+ # Production
108
+ transport: SmartMessage::Transport::RedisTransport.new(url: ENV['REDIS_URL'])
109
+ ```
110
+
111
+ #### Microservices Architecture
112
+ ```ruby
113
+ # High-availability critical messages
114
+ transport: [
115
+ SmartMessage::Transport::RedisTransport.new(url: primary_redis),
116
+ SmartMessage::Transport::RedisTransport.new(url: backup_redis),
117
+ SmartMessage::Transport::StdoutTransport.new(file_path: '/var/log/audit.log')
118
+ ]
119
+ ```
120
+
121
+ #### Event-Driven System
122
+ ```ruby
123
+ # Events with monitoring
124
+ transport: [
125
+ SmartMessage::Transport::RedisTransport.new(url: event_redis),
126
+ SmartMessage::Transport::StdoutTransport.new(
127
+ format: :jsonl,
128
+ file_path: '/var/log/events.log'
129
+ )
130
+ ]
131
+ ```
132
+
133
+ ## Decision Tree
134
+
135
+ ### Step 1: Environment Classification
136
+ ```
137
+ Are you in...?
138
+ ├── Unit Testing → Memory Transport
139
+ ├── Development → STDOUT Transport (pretty format)
140
+ ├── Integration Testing → STDOUT Transport (jsonl format)
141
+ └── Production → Continue to Step 2
142
+ ```
143
+
144
+ ### Step 2: Message Criticality (Production)
145
+ ```
146
+ How critical are your messages?
147
+ ├── Low criticality → Redis Transport (single)
148
+ ├── Medium criticality → Redis + STDOUT file logging
149
+ └── High criticality → Multi-transport (Redis primary + backup + audit)
150
+ ```
151
+
152
+ ### Step 3: Scale Requirements
153
+ ```
154
+ Expected message volume?
155
+ ├── Low (<1K/day) → Any transport suitable
156
+ ├── Medium (1K-100K/day) → Redis Transport recommended
157
+ └── High (>100K/day) → Redis Transport + performance tuning
158
+ ```
159
+
160
+ ### Step 4: Integration Requirements
161
+ ```
162
+ Need external integration?
163
+ ├── Log aggregation → STDOUT Transport (jsonl to file)
164
+ ├── Monitoring systems → Multi-transport (Redis + STDOUT)
165
+ ├── Audit requirements → Multi-transport with file logging
166
+ └── None → Single transport sufficient
167
+ ```
168
+
169
+ ## Configuration Examples
170
+
171
+ ### Environment-Based Configuration
172
+ ```ruby
173
+ class ApplicationMessage < SmartMessage::Base
174
+ transport case Rails.env
175
+ when 'test'
176
+ SmartMessage::Transport::MemoryTransport.new(auto_process: true)
177
+ when 'development'
178
+ SmartMessage::Transport::StdoutTransport.new(
179
+ format: :pretty,
180
+ loopback: true
181
+ )
182
+ when 'staging'
183
+ [
184
+ SmartMessage::Transport::RedisTransport.new(url: ENV['REDIS_URL']),
185
+ SmartMessage::Transport::StdoutTransport.new(
186
+ format: :jsonl,
187
+ file_path: '/var/log/staging.log'
188
+ )
189
+ ]
190
+ when 'production'
191
+ [
192
+ SmartMessage::Transport::RedisTransport.new(url: ENV['PRIMARY_REDIS_URL']),
193
+ SmartMessage::Transport::RedisTransport.new(url: ENV['BACKUP_REDIS_URL']),
194
+ SmartMessage::Transport::StdoutTransport.new(
195
+ format: :jsonl,
196
+ file_path: '/var/log/production.log'
197
+ )
198
+ ]
199
+ end
200
+ end
201
+ ```
202
+
203
+ ### Message-Type Based Selection
204
+ ```ruby
205
+ # High-volume, low-criticality events
206
+ class UserActivityMessage < SmartMessage::Base
207
+ transport SmartMessage::Transport::RedisTransport.new(url: ENV['REDIS_URL'])
208
+ end
209
+
210
+ # Critical business events
211
+ class PaymentProcessedMessage < SmartMessage::Base
212
+ transport [
213
+ SmartMessage::Transport::RedisTransport.new(url: ENV['PRIMARY_REDIS_URL']),
214
+ SmartMessage::Transport::RedisTransport.new(url: ENV['BACKUP_REDIS_URL']),
215
+ SmartMessage::Transport::StdoutTransport.new(
216
+ format: :jsonl,
217
+ file_path: '/var/log/payments.log'
218
+ )
219
+ ]
220
+ end
221
+
222
+ # Development/debugging messages
223
+ class DebugMessage < SmartMessage::Base
224
+ transport SmartMessage::Transport::StdoutTransport.new(
225
+ format: :pretty,
226
+ loopback: true
227
+ )
228
+ end
229
+ ```
230
+
231
+ ## Performance Considerations
232
+
233
+ ### Latency Comparison
234
+ | Transport | Typical Latency | Best Use |
235
+ |-----------|----------------|----------|
236
+ | Memory | ~0.01ms | Unit tests, development |
237
+ | STDOUT | ~1ms | Logging, debugging |
238
+ | Redis | ~1ms | Production messaging |
239
+ | Multi-transport | Sum of individual transports | Critical messages |
240
+
241
+ ### Throughput Comparison
242
+ | Transport | Throughput | Limiting Factor |
243
+ |-----------|------------|----------------|
244
+ | Memory | Highest | CPU and memory |
245
+ | STDOUT | Medium | I/O operations |
246
+ | Redis | High | Network and Redis performance |
247
+ | Multi-transport | Lowest individual transport | Sequential processing |
248
+
249
+ ### Resource Usage
250
+ | Transport | Memory Usage | External Dependencies | Setup Complexity |
251
+ |-----------|--------------|----------------------|------------------|
252
+ | Memory | Grows with volume | None | Minimal |
253
+ | STDOUT | Minimal | None | Minimal |
254
+ | Redis | Low | Redis server | Medium |
255
+ | File | Minimal | None | Minimal |
256
+
257
+ ## Migration Strategies
258
+
259
+ ### Development to Production
260
+ ```ruby
261
+ # Phase 1: Development (Memory/STDOUT)
262
+ transport: SmartMessage::Transport::MemoryTransport.new
263
+
264
+ # Phase 2: Integration Testing (STDOUT with file)
265
+ transport: SmartMessage::Transport::StdoutTransport.new(
266
+ format: :jsonl,
267
+ file_path: '/tmp/integration.log'
268
+ )
269
+
270
+ # Phase 3: Staging (Redis + logging)
271
+ transport: [
272
+ SmartMessage::Transport::RedisTransport.new(url: staging_redis),
273
+ SmartMessage::Transport::StdoutTransport.new(file_path: '/var/log/staging.log')
274
+ ]
275
+
276
+ # Phase 4: Production (Multi-transport)
277
+ transport: [
278
+ SmartMessage::Transport::RedisTransport.new(url: primary_redis),
279
+ SmartMessage::Transport::RedisTransport.new(url: backup_redis)
280
+ ]
281
+ ```
282
+
283
+ ### Transport Evolution
284
+ ```ruby
285
+ # Start simple
286
+ class MyMessage < SmartMessage::Base
287
+ transport SmartMessage::Transport::MemoryTransport.new
288
+ end
289
+
290
+ # Add logging
291
+ class MyMessage < SmartMessage::Base
292
+ transport SmartMessage::Transport::StdoutTransport.new(format: :jsonl)
293
+ end
294
+
295
+ # Scale to production
296
+ class MyMessage < SmartMessage::Base
297
+ transport SmartMessage::Transport::RedisTransport.new(url: ENV['REDIS_URL'])
298
+ end
299
+
300
+ # Add redundancy
301
+ class MyMessage < SmartMessage::Base
302
+ transport [
303
+ SmartMessage::Transport::RedisTransport.new(url: ENV['PRIMARY_REDIS']),
304
+ SmartMessage::Transport::RedisTransport.new(url: ENV['BACKUP_REDIS'])
305
+ ]
306
+ end
307
+ ```
308
+
309
+ ## Best Practices
310
+
311
+ ### General Guidelines
312
+ 1. **Start Simple**: Begin with Memory/STDOUT transports in development
313
+ 2. **Match Environment**: Use appropriate transports for each environment
314
+ 3. **Consider Criticality**: More critical messages need more redundant transports
315
+ 4. **Monitor Performance**: Track latency and throughput in production
316
+ 5. **Plan Migration**: Design transport evolution from development to production
317
+
318
+ ### Transport-Specific
319
+ - **Memory**: Use in tests and development only, set reasonable message limits
320
+ - **STDOUT**: Use `:pretty` for development, `:jsonl` for structured logging
321
+ - **Redis**: Configure proper connection pooling and reconnection settings
322
+ - **Multi-transport**: Limit to 2-4 transports, order by speed/criticality
323
+
324
+ ### Environment Configuration
325
+ - **Development**: Readable formats, loopback enabled for testing
326
+ - **Testing**: Fast, isolated transports with deterministic behavior
327
+ - **Staging**: Production-like configuration with additional logging
328
+ - **Production**: Redundant, monitored, with proper error handling
329
+
330
+ ## Troubleshooting
331
+
332
+ ### Common Issues
333
+
334
+ **Slow message publishing**
335
+ - Check multi-transport ordering (put fastest first)
336
+ - Verify Redis connection health
337
+ - Monitor file I/O performance
338
+
339
+ **Messages not appearing**
340
+ - Verify transport configuration matches environment
341
+ - Check Redis connectivity and permissions
342
+ - Ensure file paths are writable
343
+
344
+ **Memory issues**
345
+ - Set limits on Memory transport
346
+ - Monitor multi-transport memory usage
347
+ - Check for message accumulation in development
348
+
349
+ **Test failures**
350
+ - Use Memory transport for predictable test behavior
351
+ - Clear messages between tests
352
+ - Mock external transport dependencies
353
+
354
+ ## Related Documentation
355
+
356
+ - [Multi-Transport Publishing](../transports/multi-transport.md) - Detailed multi-transport patterns
357
+ - [Memory Transport](../transports/memory-transport.md) - Development and testing transport
358
+ - [Redis Transport](../transports/redis-transport.md) - Production messaging transport
359
+ - [STDOUT Transport](../transports/stdout-transport.md) - Output and logging transport
360
+ - [File Transport](../transports/file-transport.md) - Base class for file-based transports
361
+ - [Transport Overview](../reference/transports.md) - Technical transport reference
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,64 @@ 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
- Perfect for development, debugging, and logging scenarios.
36
+ **Publish-only transport** perfect for debugging, logging, and integration with external systems. Built as a minimal subclass of FileTransport, inheriting comprehensive formatting and IO handling capabilities.
18
37
 
19
38
  **Features:**
20
- - Outputs messages to console or file
21
- - Optional loopback for testing subscriptions
22
- - Human-readable message formatting
39
+ - **Publish-only**: No message processing or loopback capability
40
+ - **Three output formats**: `:jsonl` (default), `:pretty` (amazing_print), `:json` (compact)
41
+ - **Flexible output**: Defaults to STDOUT but can write to files
42
+ - **Smart IO handling**: Automatically handles both IO objects and file paths
43
+ - Subscription attempts are ignored with warning logs
44
+ - Perfect for piping to external tools and log aggregators
23
45
  - No external dependencies
24
46
 
47
+ **📚 See [STDOUT Transport Documentation](../transports/stdout-transport.md) for comprehensive usage examples.**
48
+
25
49
  **Usage:**
26
50
 
27
51
  ```ruby
28
- # Basic STDOUT output
29
- transport = SmartMessage::Transport.create(:stdout)
52
+ # Basic STDOUT output with default JSONL format
53
+ transport = SmartMessage::Transport::StdoutTransport.new
30
54
 
31
- # With loopback enabled (messages get processed locally)
32
- transport = SmartMessage::Transport.create(:stdout, loopback: true)
55
+ # JSON Lines format - one message per line (default)
56
+ transport = SmartMessage::Transport::StdoutTransport.new(format: :jsonl)
33
57
 
34
- # Output to file instead of console
35
- transport = SmartMessage::Transport.create(:stdout, output: "messages.log")
58
+ # Pretty-printed format with amazing_print for debugging
59
+ transport = SmartMessage::Transport::StdoutTransport.new(format: :pretty)
60
+
61
+ # Compact JSON format without newlines
62
+ transport = SmartMessage::Transport::StdoutTransport.new(format: :json)
63
+
64
+ # Output to file instead of STDOUT
65
+ transport = SmartMessage::Transport::StdoutTransport.new(file_path: "messages.log")
36
66
 
37
67
  # Configure in message class
38
68
  class LogMessage < SmartMessage::Base
@@ -40,25 +70,44 @@ class LogMessage < SmartMessage::Base
40
70
  property :message
41
71
 
42
72
  config do
43
- transport SmartMessage::Transport.create(:stdout,
44
- output: "app.log",
45
- loopback: false
73
+ transport SmartMessage::Transport::StdoutTransport.new(
74
+ format: :json,
75
+ file_path: "app.log"
46
76
  )
47
77
  end
48
78
  end
49
79
  ```
50
80
 
51
81
  **Options:**
52
- - `loopback` (Boolean): Whether to process published messages locally (default: false)
53
- - `output` (String|IO): Output destination - filename string or IO object (default: $stdout)
82
+ - `format` (Symbol): Output format - `:jsonl` (default), `:pretty`, `:json`
83
+ - `file_path` (String|IO): Output destination - filename string or IO object (default: `$stdout`)
84
+ - All FileTransport options are inherited and available
85
+
86
+ **Important:** For local message processing during development, use **MemoryTransport** instead.
87
+
88
+ **Format Examples:**
54
89
 
55
- **Example Output:**
90
+ **JSONL Format (default):**
91
+ ```json
92
+ {"_sm_header":{"uuid":"abc-123","message_class":"DemoMessage"},"first_name":"Alice","last_name":"Johnson"}
93
+ {"_sm_header":{"uuid":"def-456","message_class":"DemoMessage"},"first_name":"Bob","last_name":"Smith"}
56
94
  ```
57
- ===================================================
58
- == SmartMessage Published via STDOUT Transport
59
- == Header: #<SmartMessage::Header:0x... @uuid="abc-123", @message_class="MyMessage", ...>
60
- == Payload: {"user_id":123,"action":"login","timestamp":"2025-08-17T10:30:00Z"}
61
- ===================================================
95
+
96
+ **Pretty Format:**
97
+ ```ruby
98
+ {
99
+ "_sm_header" => {
100
+ "uuid" => "abc-123",
101
+ "message_class" => "DemoMessage"
102
+ },
103
+ "first_name" => "Alice",
104
+ "last_name" => "Johnson"
105
+ }
106
+ ```
107
+
108
+ **JSON Format:**
109
+ ```json
110
+ {"_sm_header":{"uuid":"abc-123"},"first_name":"Alice"}{"_sm_header":{"uuid":"def-456"},"first_name":"Bob"}
62
111
  ```
63
112
 
64
113
  ### Memory Transport
@@ -421,11 +470,11 @@ end
421
470
  order = OrderMessage.new(order_id: "123", amount: 99.99)
422
471
 
423
472
  order.config do
424
- # This instance will use STDOUT instead of memory
425
- transport SmartMessage::Transport.create(:stdout, loopback: true)
473
+ # This instance will use STDOUT instead of memory (publish-only)
474
+ transport SmartMessage::Transport::StdoutTransport.new(format: :json)
426
475
  end
427
476
 
428
- order.publish # Uses STDOUT transport
477
+ order.publish # Uses STDOUT transport (publish-only)
429
478
  ```
430
479
 
431
480
  ### Runtime Transport Switching
@@ -490,10 +539,10 @@ transport = SmartMessage::Transport.create(:custom,
490
539
  Each transport may have specific options:
491
540
 
492
541
  ```ruby
493
- # STDOUT specific
494
- SmartMessage::Transport.create(:stdout,
495
- loopback: true,
496
- output: "/var/log/messages.log"
542
+ # STDOUT specific (publish-only)
543
+ SmartMessage::Transport::StdoutTransport.new(
544
+ format: :jsonl, # :jsonl (default), :pretty, :json
545
+ file_path: "/var/log/messages.log"
497
546
  )
498
547
 
499
548
  # Memory specific