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:
1 parent
96934b6824
commit
8dd42d24bc
3 files changed
+32
-6
No files matched your search
@@ -88,7 +88,10 @@ frames.json // mounted; not in image
|
||||
"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": {
|
||||
@@ -170,7 +173,8 @@ For each upload:
|
||||
## MQTT
|
||||
|
||||
- `MQTTnet` v4 with `IMqttClient` wrapped in a hosted service (`MqttPublisher : IHostedService`).
|
||||
- Single persistent connection with `WithReconnectDelay` and `WithCleanSession(false)`. Connection state surfaced to `/health`.
|
||||
- Single persistent connection with `WithCleanSession(false)`, `WithKeepAlivePeriod(KeepAliveSeconds)` and `WithTimeout(ConnectTimeoutSeconds)`. Connection state surfaced to `/health`.
|
||||
- **Reconnect** (SPEC.md §5.2): `IMqttClient` has no built-in reconnect, so `MqttPublisher` owns it. A `DisconnectedAsync` handler logs the reason and signals a bounded(1) `_reconnect` channel — it never calls `ConnectAsync` itself, so connects are never concurrent. `ExecuteAsync` waits on that signal (or a safety timeout equal to the last backoff value, in case an event is missed), then retries `ConnectAsync` on the `ReconnectBackoffSeconds` schedule until connected. On success it resets the schedule and wakes the retry loop so queued publishes drain immediately.
|
||||
- Publish: `topic = {BaseTopic}/{normalized-mac}`, payload bytes `"update"`, QoS 1, not retained.
|
||||
- **Failure handling**: `MqttPublisher.PublishAsync` returns a `Result` (success/failure). If failure, the publisher enqueues the (topic, payload) into an in-memory `Channel<Pending>` and a background loop drains it with the configured backoff sequence. The upload response includes `mqttPublished: false` so callers know.
|
||||
|
||||
@@ -203,6 +207,8 @@ No controller/integration tests in v1 — pipeline correctness is the load-beari
|
||||
4. Subscribe with `mosquitto_sub -t 'frames/#' -v` → confirm `frames/aabbccddeeff update` appears within ~1s of the upload.
|
||||
5. Repeat with `/image-url` and a public image URL.
|
||||
6. Concurrency check: fire two `curl` uploads to the same frame in parallel → both return 200, only one final PNG on disk, two MQTT publishes (in serial order).
|
||||
7. Stop the broker, upload an image → response is 200 with `mqttPublished: false`, PNG saved, log shows retry attempts. Start the broker → background retry publishes successfully.
|
||||
7. Stop the broker, upload an image → response is 200 with `mqttPublished: false`, PNG saved, log shows the disconnect reason and backoff reconnect attempts. Start the broker → service reconnects without a restart, `/health` flips back to `mqttConnected: true`, and the queued publish goes out immediately.
|
||||
7a. Half-open link: `docker network disconnect <net> <frame-processor container>` → disconnect logged within ~1.5 × `KeepAliveSeconds`; reconnect the network → service recovers on its own.
|
||||
7b. ClientId collision: run a second instance with the same `ClientId` against the same broker → logs show `SessionTakenOver`. Use a distinct `Mqtt__ClientId` for local dev.
|
||||
8. Run `dotnet test` → golden-image fixtures pass.
|
||||
9. Power on the actual Spectra 6 frame mounted with the new firmware → it fetches the PNG and renders it correctly with the expected color mapping.
|
||||
Reference in new issue
Block a user