π‘ Unidirectional HTTP Streaming & Pub/Sub Telemetry Broker Governance
Modern distributed systems often require streaming architectures beyond standard bidirectional WebSockets. When the client only needs a continuous flow of unidirectional push updates from the serverβsuch as live LLM token generations, financial tickers, or build execution logsβServer-Sent Events (SSE) provide a lightweight, standard HTTP solution using the text/event-stream media type, built-in reconnection protocols, and Last-Event-ID tracking. Conversely, edge computing, connected vehicles, and IoT sensor meshes rely on MQTT (Message Queuing Telemetry Transport), a binary publish/subscribe messaging protocol engineered for constrained network bandwidth, high-latency links, and unreliable connectivity. Postman supports testing both paradigms: natively consuming and validating continuous SSE streams over standard HTTP requests, and connecting directly to MQTT brokers (v3.1.1 and v5.0) to subscribe to topic hierarchies, publish payloads across distinct Quality of Service (QoS) levels, and verify retained telemetry states.
ENTERPRISE REAL-TIME STREAMING ARCHITECTURAL MATRIX:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β ARCHITECTURAL ATTRIBUTE β SERVER-SENT EVENTS (SSE) β MQTT (TELEMETRY TRANSPORT) β WEBSOCKETS (RFC 6455) β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
β Transport Protocol β HTTP/1.1 or HTTP/2 over TLS β Raw TCP / TLS or WebSockets β Upgraded TCP Socket (ws/wss) β
β Communication Pattern β Unidirectional (Server βββΊ C)β Pub/Sub Broker Pattern (M:N) β Full-Duplex Bidirectional β
β Media / Framing Type β text/event-stream (Textual) β Binary Packet Headers (Compact) Frame-based (Text or Binary) β
β Reconnection Model β Native browser Last-Event-ID β Clean Session flag + Broker β Manual client reconnection β
β Delivery Guarantees β Best-effort streaming β QoS 0, QoS 1, QoS 2 tiers β Application-layer ACK needed β
β Proxy & Firewall Traver.β Native (Standard HTTP/HTTPS) β Needs MQTT Port 1883/8883 β Usually traverses HTTP/80/443 β
β Primary Enterprise Uses β LLM token streaming, Tickers β IoT telemetry, Smart meters β Multiplayer, chat, orderbooks β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ
SSE PROTOCOL WIRE FORMATTING: MQTT PUB/SUB BROKER TOPOGRAPHY:
ββββββββββββββββββββββββββββββββββββββββββββ βββββββββββββββ PUBLISH (QoS 1) βββββββββββββββ
β HTTP/1.1 200 OK β β Sensor Node β βββββββββββββββββββΊ β MQTT Broker β
β Content-Type: text/event-stream β βββββββββββββββ ββββββββ¬βββββββ
β Cache-Control: no-cache β β
β Connection: keep-alive β βΌ FORWARD TO SUBSCRIBERS
β β βββββββββββββββ
β id: 1042 β β Postman QA β (Subscribed to
β event: student_enrolled β β Test Client β students/+/events)
β data: {"studentId": "STU-88219"} β βββββββββββββββ
β β
ββββββββββββββββββββββββββββββββββββββββββββ
text/event-stream contract. Details the mandatory HTTP response headers, event framing blocks (event:, id:, data:, retry:), and double-newline terminators.
-- 1. CLIENT DISPATCH: INITIATING AN SSE STREAM --
GET /api/v1/telemetry/live-stream HTTP/1.1
Host: api.nikita-infotech.com
Accept: text/event-stream
Cache-Control: no-cache
Authorization: Bearer {{activeBearerToken}}
-- 2. MANDATORY SERVER RESPONSE HEADERS --
HTTP/1.1 200 OK
Content-Type: text/event-stream; charset=utf-8
Cache-Control: no-cache, no-transform
Connection: keep-alive
X-Accel-Buffering: no <-- Crucial for NGINX/reverse proxies to prevent stream buffering!
-- 3. CHUNKS STREAMING OVER TIME ACROSS THE OPEN HTTP CONNECTION: --
# EVENT 1: Standard data payload
id: evt_001
event: candidate_status
data: {"studentId": "STU-88219", "status": "APPLICATION_SUBMITTED"}
# EVENT 2: Multi-line JSON data payload (Each line prefixed with 'data:')
id: evt_002
event: tuition_settled
data: {
data: "studentId": "STU-88219",
data: "amount": 14999.00,
data: "currency": "INR"
data: }
# EVENT 3: Heartbeat comment frame (Ignored by client parsers, prevents proxy timeouts)
: keepalive ping - timestamp 1793524800
# EVENT 4: Client reconnect timing directive (Instructs client to wait 5000ms before reconnecting)
retry: 5000
id: evt_003
event: grade_finalized
data: {"studentId": "STU-88219", "courseCode": "API-PRO-101", "grade": "A"}
text/event-stream MIME type, disables cache buffering, and keeps the connection alive.
// ==============================================================================
// STEP: GET /api/v1/telemetry/live-stream - TESTS TAB
// Headers Sent: Accept: text/event-stream
// ==============================================================================
// 1. Verify HTTP Transport Handshake Status
pm.test("[SSE TRANSPORT] Server returned HTTP 200 OK", function () {
pm.response.to.have.status(200);
});
// 2. Validate Mandatory Content-Type Header
pm.test("[SSE MEDIA TYPE] Content-Type strictly conforms to text/event-stream", function () {
pm.response.to.have.header("Content-Type");
const contentType = pm.response.headers.get("Content-Type");
pm.expect(contentType).to.include("text/event-stream");
});
// 3. Validate Caching & Proxy Buffering Headers
pm.test("[SSE HEADERS] Directives prevent caching and proxy buffering", function () {
// Cache-Control must prohibit caching
pm.response.to.have.header("Cache-Control");
const cacheControl = pm.response.headers.get("Cache-Control");
pm.expect(cacheControl).to.include("no-cache");
// Connection must be keep-alive
if (pm.response.headers.has("Connection")) {
pm.expect(pm.response.headers.get("Connection")).to.match(/keep-alive/i);
}
// NGINX Proxy Buffering Defense Check (If present)
if (pm.response.headers.has("X-Accel-Buffering")) {
pm.expect(pm.response.headers.get("X-Accel-Buffering")).to.eql("no");
}
});
// 4. Validate SSE Frame Syntax in Response Body
pm.test("[SSE SYNTAX] Body contains valid event, id, or data stream blocks", function () {
const rawBody = pm.response.text();
pm.expect(rawBody).to.match(/(data:|event:|id:)/);
});
event, id, and data blocks from the buffered HTTP response string, converts embedded JSON payloads into objects, and asserts business assertions.
// ==============================================================================
// TESTS TAB: Custom SSE Chunk Parser & Payload Validator
// ==============================================================================
function parseSseStream(rawText) {
const events = [];
// Split stream by double newlines (\n\n or \r\n\r\n) that separate SSE blocks
const rawBlocks = rawText.split(/\r?\n\r?\n/);
rawBlocks.forEach(block => {
const trimmed = block.trim();
if (!trimmed || trimmed.startsWith(":")) return; // Skip empty blocks and heartbeat comments
const eventObj = { event: "message", id: null, data: "" };
const lines = trimmed.split(/\r?\n/);
lines.forEach(line => {
if (line.startsWith("event:")) {
eventObj.event = line.replace(/^event:\s*/, "").trim();
} else if (line.startsWith("id:")) {
eventObj.id = line.replace(/^id:\s*/, "").trim();
} else if (line.startsWith("data:")) {
const dataSlice = line.replace(/^data:\s*/, "");
eventObj.data += (eventObj.data ? "\n" : "") + dataSlice;
} else if (line.startsWith("retry:")) {
eventObj.retry = parseInt(line.replace(/^retry:\s*/, ""), 10);
}
});
// Parse data string as JSON if applicable
try {
eventObj.parsedData = JSON.parse(eventObj.data);
} catch (e) {
eventObj.parsedData = eventObj.data;
}
events.push(eventObj);
});
return events;
}
// Execute Parser
const parsedEvents = parseSseStream(pm.response.text());
console.log(`[*] Parsed ${parsedEvents.length} SSE events from stream buffer.`);
pm.test("[SSE STREAM INTEGRITY] Successfully parsed multiple structured SSE events", function () {
pm.expect(parsedEvents.length).to.be.at.least(1);
});
pm.test("[SSE EVENT AUDIT] tuition_settled event carries expected monetary contract", function () {
// Locate specific event block
const tuitionEvent = parsedEvents.find(e => e.event === "tuition_settled");
pm.expect(tuitionEvent, "Missing 'tuition_settled' event in stream!").to.not.be.undefined;
// Validate event metadata and payload
pm.expect(tuitionEvent.id).to.match(/^evt_[0-9]+$/);
pm.expect(tuitionEvent.parsedData).to.be.an("object");
pm.expect(tuitionEvent.parsedData.amount).to.equal(14999.00);
pm.expect(tuitionEvent.parsedData.currency).to.eql("INR");
// Cache Last-Event-ID for reconnection testing in Example 4
pm.environment.set("lastReceivedSseId", tuitionEvent.id);
console.log(`[β] Captured Last-Event-ID: ${tuitionEvent.id}`);
});
Last-Event-ID header into a reconnect request, asserting that the server resumes the stream from that exact event without duplicating older entries.
// ==============================================================================
// 1. PRE-REQUEST SCRIPT: Simulating Client Reconnection after Socket Drop
// Endpoint: GET /api/v1/telemetry/live-stream
// ==============================================================================
const lastEventId = pm.environment.get("lastReceivedSseId");
if (lastEventId) {
// Inject RFC W3C Last-Event-ID header to resume stream from previous point
pm.request.headers.upsert({
key: "Last-Event-ID",
value: lastEventId
});
console.log(`[+] Injected 'Last-Event-ID: ${lastEventId}' for stream resumption.`);
}
// ==============================================================================
// 2. TESTS TAB: Assert Resumed Stream Integrity
// ==============================================================================
pm.test("[SSE RESUME CONTRACT] Stream resumes strictly AFTER Last-Event-ID", function () {
pm.response.to.have.status(200);
const events = parseSseStream(pm.response.text());
const resumeId = pm.environment.get("lastReceivedSseId");
if (resumeId && events.length > 0) {
// Confirm server did NOT replay the already-received event
const hasReplayedEvent = events.some(e => e.id === resumeId);
pm.expect(hasReplayedEvent, `Server replayed event '${resumeId}' that was already acknowledged!`).to.be.false;
// Verify the first event in the resumed stream comes strictly after the resume point
console.log(`[β] Resumed stream started cleanly with event ID: ${events[0].id}`);
}
});
mqtt://) and TLS (mqtts://) brokers, sets client identifiers, configures Keep Alive intervals, and handles Clean Session flags.
POSTMAN MQTT CLIENT REQUEST CONFIGURATION:
1. CREATE MQTT REQUEST:
- Click "New" -> Select "MQTT".
- Or click the dropdown next to the "+" tab -> Select "MQTT Request".
2. CONFIGURE BROKER ADDRESS & PROTOCOL:
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SETTING β CONFIGURATION VALUE / EXPRESSION β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Protocol Scheme β mqtts:// (TLS Encrypted) or mqtt:// (Plain TCP) β
β Broker Address β mqtts://broker.nikita-infotech.com:8883 β
β MQTT Version β 3.1.1 (Standard) or 5.0 (Modern Enterprise) β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
3. CONFIGURE CLIENT IDENTITY & CREDENTIALS (Connect Tab):
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PARAMETER β CONFIGURED VALUE β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Client ID β postman-qa-{{$randomUUID}} (Unique ID prevents broker kick) β
β Username β {{mqttUsername}} β
β Password β {{mqttPassword}} β
β Clean Session / Start β True (Starts fresh session; broker discards old queue) β
β Keep Alive β 60 seconds (Heartbeat interval) β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
4. CONNECT:
- Click "Connect". Status transitions: Connecting βββΊ Connected (Green dot).
- The connection remains active for real-time publishing and subscribing.
+) and multi-level (#) wildcards to monitor telemetry messages published across tenants and microservice nodes.
MQTT TOPIC HIERARCHY & WILDCARD SPECIFICATION:
Topic Levels are delimited by forward slashes (/), representing hierarchical resource trees:
institutions / <institutionId> / departments / <deptCode> / students / <studentId> / events
WILDCARD OPERATOR SPECIFICATIONS:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββ
β OPERATOR β EXAMPLE PATTERN β MATCHING BEHAVIOR & SCOPE β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€
β Single-Level (+) β institutions/+/events β Matches EXACTLY ONE topic level: β
β β β β institutions/pune-01/events β
β β β β institutions/mumbai-02/events β
β β β β institutions/pune-01/dept/events (2 lvls) β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββ€
β Multi-Level (#) β institutions/pune-01/# β Matches ANY NUMBER of trailing levels: β
β (Must be final char!) β β β institutions/pune-01/events β
β β β β institutions/pune-01/depts/cs/students β
β β β β institutions/pune-01/sensors/temp/room101 β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββ
CONFIGURING SUBSCRIPTIONS IN POSTMAN:
1. In the "Subscriptions" tab, click "Add Topic".
2. Topic: institutions/+/departments/CS/students/#
3. Set Subscription QoS: QoS 1 (At least once).
4. Click "Subscribe". Incoming messages appear in real-time in the Message Stream panel.
MQTT QUALITY OF SERVICE (QoS) DELIVERY SEMANTICS:
ββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β QoS TIER β PROTOCOL GUARANTEE β WIRE HANDSHAKE & OVERHEAD β
ββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β QoS 0 β At most once (Fire-and-forgetβ 1 Packet (PUBLISH). No acknowledgment; messages may β
β β Best-effort delivery) β drop if network partitions occur. β
ββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β QoS 1 β At least once (Guaranteed β 2 Packets (PUBLISH βββΊ PUBACK). Resends until ACKed; β
β β delivery, duplicates possibleβ duplicates possible if ACK packets drop. β
ββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β QoS 2 β Exactly once (Guaranteed β 4-Step Handshake (PUBLISH βββΊ PUBREC βββΊ PUBREL βββΊ β
β β zero loss, zero duplicates) β PUBCOMP). Highest overhead; critical financial records. β
ββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PUBLISHING A TEST EVENT IN POSTMAN:
Topic: institutions/pune-01/departments/CS/students/STU-88219/events
QoS Level: 1 (At least once)
Retain Flag: False
Payload (JSON):
{
"eventId": "{{$randomUUID}}",
"eventType": "STUDENT_CREDIT_MUTATION",
"studentId": "STU-88219",
"mutatedCredits": 5,
"updatedBy": "admin.nikita",
"publishedEpoch": {{$timestamp}}
}
- Click "Send". Postman dispatches the packet and confirms delivery upon receiving the broker's PUBACK.
TESTING MQTT RETAINED MESSAGES & LAST WILL AND TESTAMENT:
1. RETAINED MESSAGE VERIFICATION WORKFLOW:
- Topic: institutions/pune-01/gateways/GW-01/status
- Retain Flag: [CHECKED] (True)
- Payload: { "gatewayStatus": "ONLINE", "firmware": "v2026.4" }
- Click "Send". The broker persists this message as the canonical status for this topic.
2. IMMEDIATE DELIVERY AUDIT ON NEW SUBSCRIPTION:
- Disconnect the client or open a second Postman MQTT tab.
- Subscribe to: institutions/pune-01/gateways/GW-01/status
- OUTCOME: The broker delivers the retained status message IMMEDIATELY upon subscribing,
even though no node is actively publishing at that moment.
3. CLEARING A RETAINED MESSAGE:
- To purge a retained message from the broker, publish an EMPTY payload (0 bytes)
with Retain: True to the exact same topic.
4. LAST WILL AND TESTAMENT (LWT) CONFIGURATION (Connect Tab):
Configure automated ungraceful disconnect alerts:
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LWT FIELD β CONFIGURED VALUE β
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β LWT Topic β institutions/pune-01/clients/{{clientId}}/status β
β LWT QoS β 1 β
β LWT Retain β True β
β LWT Message β { "status": "OFFLINE", "reason": "UNEXPECTED_DISCONNECT" } β
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- If the client drops abruptly (e.g. process crash or network partition), the broker
automatically broadcasts the LWT message to all subscribers.
SSE & MQTT SPECIFICATION & DIRECTIVE MATRIX:
βββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β PROTOCOL COMPONENT β SPECIFICATION / SYNTAX β STANDARD / RFC β PRIMARY OPERATIONAL PURPOSE β
βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββΌβββββββββββββββββββΌββββββββββββββββββββββββββββββββββ€
β SSE Content-Type β text/event-stream β W3C EventSource β Establishes unidirectional HTTP β
β SSE Data Field β data: {"key": "val"}\n\n β W3C EventSource β Transmits message payload β
β SSE Event Field β event: custom_event_name β W3C EventSource β Names specific event channel β
β SSE ID Field β id: unique_event_id β W3C EventSource β Provides stream tracking token β
β Last-Event-ID Header β Last-Event-ID: evt_002 β W3C EventSource β Resumes dropped stream without β
β MQTT Protocol Scheme β mqtt:// (1883) / mqtts://(8883)OASIS Standard β Binary IoT messaging broker β
β Single-Level Wildcard β sensors/+/temperature β MQTT 3.1.1 / 5.0 β Matches exactly 1 topic level β
β Multi-Level Wildcard β sensors/# β MQTT 3.1.1 / 5.0 β Matches all trailing levels β
β QoS 0 (At most once) β Best-effort fire-and-forget β MQTT 3.1.1 / 5.0 β Minimal overhead, drops allowed β
β QoS 1 (At least once) β Guaranteed with PUBACK retry β MQTT 3.1.1 / 5.0 β Guaranteed receipt; dupes pos. β
β QoS 2 (Exactly once) β 4-step handshake (PUBREC/COMPβ MQTT 3.1.1 / 5.0 β Zero loss, zero duplicates β
β Retained Message β Retain: True β MQTT 3.1.1 / 5.0 β Caches last message on broker β
β Last Will & Testament β LWT Topic + Message β MQTT 3.1.1 / 5.0 β Broadcasts on ungraceful drop β
βββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββ΄βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββ€
β TOP 5 STREAMING & IOT TESTING BEST PRACTICES: β
β 1. Validate X-Accel-Buffering: no on SSE: Confirm reverse proxies do not buffer real-time event chunks. β
β 2. Test Last-Event-ID reconnection: Verify server resumes streams after disconnection without dupes. β
β 3. Use unique MQTT Client IDs: Append {{$randomUUID}} to prevent clients kicking each other off brokers. β
β 4. Clear retained messages with 0-byte payloads: Purge stale retain states after completing test runs. β
β 5. Choose the right QoS level: Use QoS 1 for standard business events; reserve QoS 2 for critical data. β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ