Sub-issue of #601.
Summary
When an SSE client reconnects after a disconnect and sends a Last-Event-ID header, replay the missed events from MongoDB before switching to the live MQTT stream.
Motivation
SSE's Last-Event-ID mechanism is designed for exactly this use case. Without replay, a client that disconnects for 30 seconds during a burst of sensor events simply loses those readings. With replay, the client catches up seamlessly — critical for applications that need a complete time-series record.
Proposed behaviour
- Client connects:
GET /mqtt-sse?topic=sensors/%23 with header Last-Event-ID: <objectId>.
MqttSseService queries MongoDB for documents in the matching collection(s) where _id > lastEventId, ordered by receivedAt ascending.
- Historical documents are streamed as SSE events first.
- Once historical replay is exhausted, the connection seamlessly switches to the live MQTT fanout.
- If
mqtt-mongo-writer is not enabled, Last-Event-ID is silently ignored and the client receives only the live stream (graceful degradation).
Scope
MqttSseService detects lastEventId parameter in onConnect.
- Replay query uses the same
mongo-sink mapping from mqtt-mongo-writer config to find the target collection.
- Replay runs on a virtual thread; live messages are buffered in the per-connection queue during replay to prevent gaps at the handover point.
- Configurable
max-replay-messages to cap the replay size for very long disconnects.
- Integration test: publish 100 messages, disconnect, publish 50 more, reconnect with
Last-Event-ID, assert all 50 missed messages are replayed before live stream resumes.
Dependencies
Sub-issue of #601.
Summary
When an SSE client reconnects after a disconnect and sends a
Last-Event-IDheader, replay the missed events from MongoDB before switching to the live MQTT stream.Motivation
SSE's
Last-Event-IDmechanism is designed for exactly this use case. Without replay, a client that disconnects for 30 seconds during a burst of sensor events simply loses those readings. With replay, the client catches up seamlessly — critical for applications that need a complete time-series record.Proposed behaviour
GET /mqtt-sse?topic=sensors/%23with headerLast-Event-ID: <objectId>.MqttSseServicequeries MongoDB for documents in the matching collection(s) where_id > lastEventId, ordered byreceivedAtascending.mqtt-mongo-writeris not enabled,Last-Event-IDis silently ignored and the client receives only the live stream (graceful degradation).Scope
MqttSseServicedetectslastEventIdparameter inonConnect.mongo-sinkmapping frommqtt-mongo-writerconfig to find the target collection.max-replay-messagesto cap the replay size for very long disconnects.Last-Event-ID, assert all 50 missed messages are replayed before live stream resumes.Dependencies
mqtt-mongo-writerto be enabled; if disabled the feature degrades gracefully.