MockForge WebSocket
WebSocket mocking library for MockForge with replay, proxy, and AI-powered event generation.
This crate provides comprehensive WebSocket mocking capabilities, including:
- Replay Mode: Script and replay WebSocket message sequences
- Interactive Mode: Dynamic responses based on client messages
- AI Event Streams: Generate narrative-driven event sequences
- Proxy Mode: Forward messages to real WebSocket backends
- JSONPath Matching: Sophisticated message matching with JSONPath queries
Overview
MockForge WebSocket supports multiple operational modes:
1. Replay Mode
Play back pre-recorded WebSocket interactions from JSONL files with template expansion.
2. Proxy Mode
Forward WebSocket messages to upstream servers with optional message transformation.
3. AI Event Generation
Generate realistic event streams using LLMs based on narrative descriptions.
Quick Start
Basic WebSocket Server
use router;
async
With Latency Simulation
use router_with_latency;
use ;
# async
With Proxy Support
use router_with_proxy;
use ;
# async
AI Event Generation
Generate realistic event streams from narrative descriptions:
use ;
use RagConfig;
# async
Replay File Format
WebSocket replay files use JSON Lines (JSONL) format:
Fields:
ts: Timestamp in millisecondsdir: Direction ("in" = received, "out" = sent)text: Message content (supports template expansion)waitFor: Optional regex/JSONPath pattern to wait for
JSONPath Message Matching
Match messages using JSONPath queries:
Key Modules
- [
ai_event_generator]: AI-powered event stream generation - [
ws_tracing]: Distributed tracing integration
Examples
See the examples directory for complete working examples.
Related Crates
mockforge-core: Core mocking functionalitymockforge-data: Synthetic data generation