Represents a single Server-Sent Events message conforming to the W3C EventSource specification, holding the event type, data payload, id and retry interval that together make up one message on an SSE stream. Instances are immutable; build one directly via the constructor or, more conveniently, via the nested Builder. Call toSse() to render the message into the plain-text wire format expected by EventSource clients. SseConection and SseManager use this class to push individual events to connected clients.
Properties
| Property | Returns | Description |
|---|---|---|
| data | String | Returns the data content of this SSE message. May span multiple lines, each of which is emitted as a separate "data:" line by toSse(). |
| event | String | Returns the event type for this SSE message, which clients can subscribe to individually via addEventListener. A null event type means the message is delivered as a generic "message" event. |
| id | String | Returns the unique identifier for this SSE message, used by EventSource clients to resume a stream from the last received message after a reconnect. |
| retry | Integer | Returns the reconnection time this message tells the client to use if the connection is lost. |
Methods
getId()
Returns: String
Returns the unique identifier for this SSE message, used by EventSource clients to resume a stream from the last received message after a reconnect.
getEvent()
Returns: String
Returns the event type for this SSE message, which clients can subscribe to individually via addEventListener. A null event type means the message is delivered as a generic "message" event.
getData()
Returns: String
Returns the data content of this SSE message. May span multiple lines, each of which is emitted as a separate "data:" line by toSse().
getRetry()
Returns: Integer
Returns the reconnection time this message tells the client to use if the connection is lost.
toSse()
Returns: String
Renders this message into the plain-text Server-Sent Events wire format, with one "field: value" line per populated field and a trailing blank line marking the end of the event, ready to be written to an SSE stream.