Skip to content

MessageEvent

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/http/message-event.interface.ts

Part of: Common

MessageEvent represents a server-sent event (SSE) message in the HTTP layer. It defines the payload and optional SSE metadata used to identify events, classify them, control client reconnection timing, and send comment-only messages.

Properties

PropertyType
data`string
idstring
typestring
retrynumber
commentstring

Diagram

mermaid
graph LR
  Server[HTTP/SSE Server] --> Event[MessageEvent]
  Event --> Data[data: string | object]
  Event --> Id[id: string]
  Event --> Type[type: string]
  Event --> Retry[retry: number]
  Event --> Comment[comment: string]
  Event --> Client[SSE Client]

Usage

ts
import { MessageEvent } from '@nestjs/common';

const event: MessageEvent = {
  id: 'order-1024',
  type: 'order.updated',
  data: {
    orderId: 1024,
    status: 'shipped',
  },
  retry: 5000,
  comment: 'Order status notification',
};

// Example SSE stream emission
subscriber.next(event);

AI Coding Instructions

  • Use data for the event payload; it may be either a serialized string or a plain object.
  • Set type to a stable, consumer-friendly event name such as user.created or order.updated.
  • Provide a unique id when clients need to resume streams using the SSE Last-Event-ID mechanism.
  • Use retry in milliseconds to suggest how long SSE clients should wait before reconnecting.
  • Use comment for SSE heartbeat or informational messages that should not be treated as application event data.

Used by

4 references from 4 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (4)

  • CustomHeaderpackages/core/router/router-response-controller.ts:18
  • AdditionalHeaderspackages/core/router/sse-stream.ts:38
  • PassthroughInterceptorintegration/nest-application/sse/src/app.controller.ts:28
  • AppControllersample/28-sse/src/app.controller.ts:8

Was this page helpful?

Download as PDF
MessageEvent — NestJS head-to-head