Specify MQTT reconnect behavior

Add SPEC.md §5.2 describing reconnect requirements (backoff, keep-alive
detection, disconnect logging, unique ClientId), the new Mqtt config
keys, the matching PLAN.md design and verification steps, and
IMPLEMENTATION.md increment 6.6. Also drop the stale WithReconnectDelay
reference, which only exists on ManagedMqttClient.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
zyberzeroandClaude Opus 5.5 committed 2026-11-03 18:51:43 +01:00
1 parent 96934b6824
commit 8dd42d24bc
3 files changed
+32 -6

No files matched your search

+16 -2
View File
@@ -114,7 +114,7 @@ Fetch the most recent processed PNG for a frame.
## 5. MQTT contract
- **Broker:** configured in `appsettings.json` (host, port, credentials, TLS).
- **Client:** persistent connection with automatic reconnect; clean session = false.
- **Client:** persistent connection with automatic reconnect (see §5.2); clean session = false.
- **Publish:**
- **Topic:** `{baseTopic}/{normalized-mac}` — `baseTopic` is configurable (default `frames`); `normalized-mac` is lowercase hex with no separators (e.g., `aabbccddeeff`).
- **Payload:** the UTF-8 bytes of the literal string `update`.
@@ -127,6 +127,17 @@ The service is a publisher only. It does not subscribe to any topics.
If a publish attempt fails, the (topic, payload) is enqueued for retry. Retries occur on a configurable backoff schedule (default `[1, 2, 5, 15, 60]` seconds). A successful publish drains the corresponding queue entry. Multiple queued publishes for the same frame collapse to the most recent one.
### 5.2 Connection & reconnect
- The service connects at startup. A failed initial connect does not block startup; the service serves HTTP while reconnecting in the background.
- If the connection drops for any reason (broker restart, network loss, keep-alive timeout, session takeover, auth failure), the service reconnects **without operator action and without a process restart**.
- Reconnect attempts follow `ReconnectBackoffSeconds` (default `[1, 2, 5, 15, 30]` seconds), capped at the last value. The schedule resets after a successful connect.
- A silently dead link (half-open TCP) is detected via MQTT keep-alive within roughly 1.5 × `KeepAliveSeconds`. Each connect attempt is bounded by `ConnectTimeoutSeconds`.
- Every disconnect is logged with its reason; every failed reconnect attempt is logged with the attempt number and the delay until the next one.
- `/health` `mqttConnected` reflects the live connection state.
- Queued retries (§5.1) drain immediately after a successful reconnect.
- `ClientId` must be unique per broker. Two instances sharing one will repeatedly disconnect each other (`SessionTakenOver`).
## 6. Configuration
### 6.1 Application configuration — `appsettings.json`
@@ -142,7 +153,10 @@ If a publish attempt fails, the (topic, payload) is enqueued for retry. Retries
"UseTls": false,
"BaseTopic": "frames",
"PublishQos": 1,
"RetryBackoffSeconds": [1, 2, 5, 15, 60]
"RetryBackoffSeconds": [1, 2, 5, 15, 60],
"ReconnectBackoffSeconds": [1, 2, 5, 15, 30],
"KeepAliveSeconds": 15,
"ConnectTimeoutSeconds": 10
},
"ApiKey": "change-me",
"Storage": {