Skip to main content

Server-Sent Events (SSE)

TinyMQ supports Server-Sent Events (SSE) for unidirectional, real-time message streaming.

This is particularly useful for building web dashboards or live-tailing logs directly in the browser without the complexity of WebSockets.

The /stream/{topic} Endpoint

Endpoint: GET /stream/{topic}

When you connect to this endpoint, TinyMQ upgrades the request to text/event-stream and holds the connection open (Connection: keep-alive).

Like WebSockets, SSE connections operate in Spy Mode. They are non-destructive and receive a copy of every message published to the topic without dequeuing it from the actual WAL.

Example: Browser JavaScript

Because SSE is a native web standard, you can consume it directly using the built-in EventSource API in any modern browser:

const evtSource = new EventSource("http://localhost:7800/stream/my_topic");

evtSource.onmessage = function(event) {
const msg = JSON.parse(event.data);
console.log("New message:", msg.payload_text);
};

evtSource.onerror = function(err) {
console.error("Stream error:", err);
};

Example: cURL

You can use cURL to live-tail a topic from the terminal:

curl -N -H "Accept: text/event-stream" http://localhost:7800/stream/my_topic

Output:

data: {"id":"uuid...","topic":"my_topic","payload":"...","payload_text":"Hello"}

data: {"id":"uuid...","topic":"my_topic","payload":"...","payload_text":"World"}

The tmq tail Command

The official CLI includes a tail command that wraps the SSE endpoint and adds automatic reconnection logic:

tmq tail my_topic