wse-client 1.2.1 → 1.2.2
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.
- package/README.md +33 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,9 @@ The engine is Rust-accelerated via PyO3. Up to **2M msg/s** sustained throughput
|
|
|
25
25
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
|
-
### Server (Python)
|
|
28
|
+
### Server (Python) -- Router Mode
|
|
29
|
+
|
|
30
|
+
Embed WSE into your existing FastAPI app on the same port:
|
|
29
31
|
|
|
30
32
|
```python
|
|
31
33
|
from fastapi import FastAPI
|
|
@@ -43,6 +45,31 @@ app.include_router(wse, prefix="/wse")
|
|
|
43
45
|
await wse.publish("notifications", {"text": "Order shipped!", "order_id": 42})
|
|
44
46
|
```
|
|
45
47
|
|
|
48
|
+
### Server (Python) -- Standalone Mode
|
|
49
|
+
|
|
50
|
+
Run the Rust WebSocket server on a dedicated port for maximum throughput:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from wse_server._wse_accel import RustWSEServer
|
|
54
|
+
|
|
55
|
+
server = RustWSEServer(
|
|
56
|
+
"0.0.0.0", 5006,
|
|
57
|
+
max_connections=10000,
|
|
58
|
+
jwt_secret=b"your-secret-key", # Rust JWT validation in handshake
|
|
59
|
+
jwt_issuer="your-app",
|
|
60
|
+
jwt_audience="your-api",
|
|
61
|
+
)
|
|
62
|
+
server.start()
|
|
63
|
+
|
|
64
|
+
# Drain inbound events in a background thread
|
|
65
|
+
while True:
|
|
66
|
+
events = server.drain_inbound(256, 50) # batch size, timeout ms
|
|
67
|
+
for event in events:
|
|
68
|
+
handle(event)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Standalone mode gives you a dedicated Rust tokio runtime on its own port -- no FastAPI overhead, no GIL on the hot path. This is how WSE achieves 2M msg/s.
|
|
72
|
+
|
|
46
73
|
### Client (React)
|
|
47
74
|
|
|
48
75
|
```tsx
|
|
@@ -217,9 +244,11 @@ Client (React + TypeScript) Server (Python + Rust)
|
|
|
217
244
|
======================== ========================
|
|
218
245
|
|
|
219
246
|
useWSE hook FastAPI Router (/wse)
|
|
220
|
-
|
|
|
221
|
-
v
|
|
222
|
-
ConnectionPool
|
|
247
|
+
| -- OR --
|
|
248
|
+
v RustWSEServer (standalone :5006)
|
|
249
|
+
ConnectionPool |
|
|
250
|
+
| (multi-endpoint, v
|
|
251
|
+
| health scoring) Rust Engine (PyO3)
|
|
223
252
|
| (multi-endpoint, | (drain mode,
|
|
224
253
|
| health scoring) | write coalescing)
|
|
225
254
|
v v
|
package/package.json
CHANGED