Package org.springframework.http.codec

# Class ServerSentEvent<T>

java.lang.Object
org.springframework.http.codec.ServerSentEvent<T>

Type Parameters:
  `T` - the type of data that this event contains

public final class ServerSentEvent<T> extends Object
Representation for a Server-Sent Event for use with Spring's reactive Web support. `Flux<ServerSentEvent>` or `Observable<ServerSentEvent>` is the reactive equivalent to Spring MVC's `SseEmitter`.

Since:
  5.0
Author:
  Sebastien Deleuze, Arjen Poutsma
See Also:
  - `ServerSentEventHttpMessageWriter`
  - Server-Sent Events

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`ServerSentEvent.Builder<T>`
A mutable builder for a `ServerSentEvent`.

## Method Summary

Modifier and Type
Method
Description
`static <T> ServerSentEvent.Builder<T>`
`builder()`
Return a builder for a `ServerSentEvent`.
`static <T> ServerSentEvent.Builder<T>`
`builder(T data)`
Return a builder for a `ServerSentEvent`, populated with the given data.
`String`
`comment()`
Return the comment of this event, if available.
`T`
`data()`
Return the `data` field of this event, if available.
`boolean`
`equals(Object other)`
`String`
`event()`
Return the `event` field of this event, if available.
`String`
`format()`
Return a StringBuilder with the id, event, retry, and comment fields fully serialized, and also appending "data:" if there is data.
`int`
`hashCode()`
`String`
`id()`
Return the `id` field of this event, if available.
`Duration`
`retry()`
Return the `retry` field of this event, if available.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Method Details

### id

@Nullable public String id()
Return the `id` field of this event, if available.

### event

@Nullable public String event()
Return the `event` field of this event, if available.

### retry

@Nullable public Duration retry()
Return the `retry` field of this event, if available.

### comment

@Nullable public String comment()
Return the comment of this event, if available.

### data

@Nullable public T data()
Return the `data` field of this event, if available.

### format

public String format()
Return a StringBuilder with the id, event, retry, and comment fields fully serialized, and also appending "data:" if there is data.

Since:
  6.2.1

### equals

public boolean equals(@Nullable Object other)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### builder

public static <T> ServerSentEvent.Builder<T> builder()
Return a builder for a `ServerSentEvent`.

Type Parameters:
  `T` - the type of data that this event contains
Returns:
  the builder

### builder

public static <T> ServerSentEvent.Builder<T> builder(T data)
Return a builder for a `ServerSentEvent`, populated with the given data.

Type Parameters:
  `T` - the type of data that this event contains
Returns:
  the builder