Files
fx-test/docs/usage.md

70 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 📖 Usage Guide
The **fx-test** stack exposes two primary interfaces:
1. **WebSocket** Realtime event channel.
2. **HTTP** RESTful configuration and monitoring.
## 1⃣ WebSocket API
The WebSocket endpoint is available on port `8080`. Common message types:
| Message Type | Description |
|--------------|-------------|
| `ping` | Health check; server replies with `pong`. |
| `subscribe` | Subscribe to a topic; server sends updates. |
| `publish` | Broadcast a message to all clients. |
Example using Node.js:
```js
const ws = require("ws");
const socket = new ws("ws://localhost:8080");
socket.on("open", () => socket.send(JSON.stringify({type:"ping"}));
socket.on("message", m => console.log("Received: ", m));
```
## 2⃣ HTTP API
### Health
```bash
GET /health
```
Response:
```json
{"status":"ok","uptime":123456}
```
### Status
```bash
GET /status
```
Returns the current number of connected WebSocket clients and processing metrics.
## 3⃣ Configuring via ENV
The stack reads the following environment variables:
| Variable | Default | Purpose |
|----------|---------|---------|
| **PORT** | `8080` | WebSocket port |
| **HTTP_PORT** | `8090` | HTTP listening port |
| **REGISTRY** | `docker.io` | Registry to fetch Docker images |
| **DEBUG** | `false` | Enable debug logging |
Set the environment variables in a `.env` file at the repo root or export them in your shell before running `run_dev.sh`.
---
## 4⃣ Extending the Stack
1. **Add a new service** Place a `Dockerfile` in `fluxer/` and reference it in the `docker-compose.yml`.
2. **Modify the relay** Edit the Erlang source in `fluxer_relay/src/relay/`. After editing, recompile with `rebar3 do compile, release` and rebuild the Docker image.
3. **Update the CI** Extend `ci/workflows/**.py` to run any new tests.