# 
        Message Store
    
The Message Store is a component of the Nekuti Matching Engine that maintains a persistent, sequenced record of all business-domain state changes. It ensures reliable message delivery to consumers through an at-least-once delivery guarantee with explicit acknowledgment.
        # 
        Tutorials
    
        # 
        Getting Started with Message Store Subscription
    
To begin consuming messages from the Message Store:
- Connect to the WebSocket feed endpoint
- Subscribe to a message store by name (use ""for the default store)
- Optionally specify a command index to resume from
- Process incoming messages
- Send periodic purge acknowledgments
For detailed endpoint specifications and examples, refer to the Swagger documentation at http://your-control-gateway:8181/docs/.
        # 
        Basic Subscription Flow
    
When establishing a subscription:
- If no command index is provided, all messages in the store are returned
- If a command index is specified, all messages after that index are sent
- If the specified index is earlier than the purged index, an error is returned
        # 
        How-To Guides
    
        # 
        How to Subscribe to a Message Store
    
Subscribe to a specific message store via WebSocket by:
- Connecting to the WebSocket feed endpoint
- Sending a subscription request with the store name
- Including the last processed command index (optional)
        # 
        How to Acknowledge Message Consumption
    
Confirm message processing by sending a purge message:
- Include the command index up to which messages have been processed
- This frees memory in the engine by removing acknowledged messages
- Regular purging prevents memory exhaustion and automatic suspension
        # 
        How to Configure Message Store Suspension
    
Protect against memory exhaustion by configuring the fail-safe suspension setting:
http://gateway:8181/MessageStore/Suspension?storeId=%22%22&maximumUnpurgedItemAgeMillis=3000000Parameters:
- storeId: The message store identifier (use- %22%22for default store)
- maximumUnpurgedItemAgeMillis: Maximum age in milliseconds (default: 6 hours = 21,600,000ms)
        # 
        How to Handle Exchange Suspension
    
When automatic suspension occurs:
- During Market Volatility: Manually suspend the exchange before recovering failed services
- Recovery Steps:
- Fix the consumer service issues
- Resume message purging
- Monitor until the oldest unpurged message age falls below the threshold
- The exchange will automatically unsuspend, or manually unsuspend when market conditions are favorable
 
        # 
        Explanation
    
        # 
        Architecture Overview
    
The Message Store operates as a sequential, append-only log where each message corresponds to state changes triggered by sequenced commands. This design ensures:
- Ordering Guarantee: Messages maintain strict sequential order based on command indices
- Reliability: At-least-once delivery with explicit acknowledgment
- Memory Efficiency: Purged messages are removed from memory
- Fault Tolerance: Automatic suspension prevents memory exhaustion
        # 
        Command Index Behavior
    
Command indices exhibit specific characteristics:
- Monotonic: Always increasing, never decreasing
- Non-Dense: Gaps exist due to read-only commands or silent updates (e.g., clock ticks)
- Multi-Message: A single command index may generate multiple messages (e.g., mark updates triggering executions and liquidations)
        # 
        Message Types
    
The Message Store captures all business-domain state changes:
- Executions
- Account transactions (deposits/withdrawals)
- Liquidations
- Funding charges
- Liveness checks
        # 
        Suspension Mechanism
    
The automatic suspension feature protects system integrity:
Suspension Triggers:
- Oldest unpurged message exceeds configured age limit
- Applies to any message store in the system
Effects During Suspension:
- New order placement blocked
- Mark updates accepted but not processed
- No liquidations occur
- Orders not triggered
Unsuspension:
- Automatic: When purging catches up and oldest message age falls below threshold
- Manual: Operators can control timing, especially important during volatile markets
- Mark effects evaluated as if submitted at unsuspension time
        # 
        Reference
    
        # 
        Configuration Parameters
    
        # 
        WebSocket Subscription Parameters
    
        # 
        Error Conditions
    
        # 
        Best Practices
    
- Regular Purging: Implement consistent purge acknowledgments to prevent memory buildup
- Index Tracking: Maintain persistent storage of last processed command index
- Suspension Monitoring: Alert on approaching suspension thresholds
- Market-Aware Recovery: During volatile markets, use manual suspension control for safer recovery
- Consumer Health Checks: Monitor consumer services to prevent purge failures
For implementation examples and detailed API specifications, consult the Swagger documentation at http://your-control-gateway:8181/docs/.