Skip to content

SSE Settings

Server-Sent Events (SSE) let a Jarvis service push a stream of events to a client over an ordinary HTTP connection. The browser's EventSource API reads the stream. SSE works in both JSON and REST modes. By default no SSE endpoints are defined, and Jarvis behaves exactly as it does without SSE support.

See Server-Sent Events for more information about using SSE with Jarvis.

SSEEndpoints

Description SSEEndpoints names the endpoints that serve event streams. It can be either:
  • a character vector of one or more endpoint names separated by commas and/or spaces
  • a vector of character vectors, one endpoint name per element. In a JSON configuration file, this is an array of strings.
Names may be written with or without a leading /. A / within a name is treated as ., so '/a/b' and 'a.b' both name the endpoint /a/b, handled by the function a.b in CodeLocation. Empty and duplicate names are ignored.
Each SSE endpoint may have a function of the same name in CodeLocation, but doesn't need one. If there is one, it must be a monadic or ambivalent function, and may return a result or not. Jarvis calls it once for each client after the stream has started. See The endpoint function.
Default '' - no SSE endpoints
Examples j.SSEEndpoints←'events'
j.SSEEndpoints←'/events, /alerts'
j.SSEEndpoints←'events' 'alerts/high'
In a JSON configuration file:
"SSEEndpoints": "events, alerts"
"SSEEndpoints": ["events", "alerts/high"]
Notes
  • SSEEndpoints is read when Jarvis starts, so changes take effect at the next Start.
  • An SSE endpoint can't also be called as an ordinary JSON or REST endpoint. Every request for an SSE endpoint's path is handled as an SSE request, and a method other than GET gets 405 (Method Not Allowed).
  • If CodeLocation contains something with an SSE endpoint's name that isn't a monadic or ambivalent function (for example a variable, a namespace or a dyadic function), Start fails with a message saying so.

SSEHeartbeatInterval

Description SSEHeartbeatInterval is the number of seconds between "heartbeats" that Jarvis sends on every open SSE stream. A heartbeat is an SSE comment (a line containing only :), which the browser doesn't pass to the page. Heartbeats do two jobs:
  • They keep proxies and load balancers from closing a stream that's been idle for a while.
  • They detect clients that have gone away. If a heartbeat can't be sent, Jarvis closes that connection.
Valid values are:
  • 0 - don't send heartbeats
  • a positive number - the number of seconds between heartbeats
Default 30
Examples j.SSEHeartbeatInterval←15 ⍝ every 15 seconds
j.SSEHeartbeatInterval←0 ⍝ no heartbeats
Notes
  • The heartbeat runs in its own thread, which starts only when SSEHeartbeatInterval is positive and SSEEndpoints isn't empty. The thread ends when the server stops.
  • SSEHeartbeatInterval is read when the server starts, so changes take effect at the next Start.
  • Many proxies close connections that are idle for 60 seconds or more. If your service sits behind one, keep the interval well below its idle timeout.
  • ConnectionTimeout doesn't apply to SSE streams: an open stream is never closed for being idle.