SSE Notification
The SSE (Server-Sent Events) notification stream is the primary mechanism for waking up a service client when new orders or commands are available. The stream sends lightweight notifications only. It never contains full order or command payloads. When a notification is received, the client should immediately poll GET /orders/location for the actual data.
Endpoint
GET https://{host}/notifications/service/streamHeaders:
| Header | Required | Description |
|---|---|---|
api_key | Yes | Service device API key |
Query parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
orderNumber | long | -1 | Last processed order number for offset-based reconnect |
commandNumber | long | 0 | Last processed command ID for offset-based reconnect |
Response: text/event-stream (SSE stream using SseEmitter)
Event Flow
Once connected, the server sends events in the following sequence:
Client Server
| |
|--- GET /notifications/service/stream --->|
| |
|<-- event: ready |
| data: {"subscriptionId": "...",|
| "locationName": "..."} |
| |
|<-- event: message | (when new orders or commands)
| data: {"apiKey": "...", |
| "licenseCode": "...", |
| "scope": "..."} |
| |
|<-- event: keepalive | (every 15 seconds)
| data: {} |1. Ready Event
On successful connection, the server immediately sends a ready event with the subscription metadata:
event: ready
data: {"subscriptionId":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","locationName":"Main Floor"}The subscriptionId uniquely identifies this SSE connection. The locationName indicates which location the client is subscribed to.
2. Message Events
When new orders or commands are available for the location, the server sends a message event with a MessagesAvailableEvent payload:
event: message
data: {"apiKey":"abc123-def456","licenseCode":"LICENSE01","scope":"SESSION"}The MessagesAvailableEvent payload:
| Field | Type | Description |
|---|---|---|
apiKey | string | The API key of the subscription. |
licenseCode | string | The license code for the tenant. |
scope | string | Either SESSION or LICENSE, indicating the broadcast scope. |
This is a signal to poll. It does not contain any order or command data.
3. Keepalive Events
The server sends a keepalive event every 15 seconds to keep the connection alive:
event: keepalive
data: {}If no keepalive is received for 60 seconds, the client should assume the connection is dead and reconnect.
Connection Timeout
The service endpoint configures its emitter with a 60-minute timeout, and the scheduler sends keepalives every 15 seconds. Handle closure, timeout, and network failure by reconnecting. Do not rely on keepalives extending the stream indefinitely.
A client can use a 60-second gap without keepalives as a local reconnect threshold. This is a suggested health check, not a server guarantee about when a network failure will be reported.
Reconnection with Offset
When reconnecting after a disconnection, pass the last processed order number and command ID as query parameters. The offsets control which pending work triggers a notification; they are not a replay log or processing acknowledgement:
curl -i -H "api_key: abc123-def456-ghi789" \
"https://{host}/notifications/service/stream?orderNumber=12345&commandNumber=42"orderNumber— The highest ordernumberyou have already processed. Pass-1or omit for no offset (start from the beginning).commandNumber— The highest command ID you have already processed. Pass0or omit for no offset.
The server uses these offsets to filter which orders and commands trigger notifications. It tracks the pushed offsets in memory for each subscription.
Error Responses
The SSE stream may return the following HTTP status codes:
| Status | Meaning |
|---|---|
| 401 | Unauthorized — Invalid or missing API key |
| 503 | Service Unavailable — Server is temporarily unavailable. Client should retry with exponential backoff |
Client Implementation Guidance
Check the stream
Use a service client that can send the api_key header. For a connection check:
curl -N -H "api_key: abc123-def456-ghi789" \
"https://{host}/notifications/service/stream?orderNumber=-1&commandNumber=0"Verify that ready reports the intended location and that keepalive events follow. Trigger a controlled test operation, watch for message, then retrieve the work with Polling. The message payload contains a credential; do not copy the raw stream into logs or support tickets.
Reconnect without losing processing state
- Close the failed stream before opening another one.
- Use bounded exponential backoff, for example 1, 2, 4, 8 seconds, capped at 60 seconds. Stop and investigate repeated failures.
- Load order and command offsets from durable processing records. Keep the two identifier sequences separate.
- Do not advance an offset past work that still needs processing or reconciliation.
- Reopen the stream and poll for pending work. A
readyevent must not reset saved offsets. - Deduplicate against durable records before repeating an external action.
Browser EventSource examples require the key in the URL. Prefer a service client with header authentication for deployed register integrations, and exclude credentials from URL and payload logging.
What the Client Must Do
- Open the SSE connection with the API key.
- On
ready, record thesubscriptionIdandlocationName. - On
message, immediately callGET /orders/location. - Keep track of the last processed
orderNumberandcommandNumberfor reconnection. - If the connection drops, reconnect with exponential backoff, passing the offset parameters.
What the SSE Stream Does NOT Do
- The SSE stream does not contain order data or command payloads. It is a wake-up signal only.
- The SSE stream does not acknowledge that you have processed orders. Processing acknowledgement happens through the status update and command response endpoints.
Next Steps
- Polling — Poll for orders and commands when notified
- Respond to Commands — Respond to commands retrieved via polling