public static interface ServerResponse.SseBuilder
Modifier and Type | Method and Description |
---|---|
ServerResponse.SseBuilder |
comment(String comment)
Add an SSE comment.
|
void |
complete()
Completes the event stream.
|
void |
data(Object object)
Add an SSE "data" line for the given object and sends the built
server-sent event to the client.
|
void |
error(Throwable t)
Completes the event stream with the given error.
|
ServerResponse.SseBuilder |
event(String eventName)
Add an SSE "event" line.
|
ServerResponse.SseBuilder |
id(String id)
Add an SSE "id" line.
|
ServerResponse.SseBuilder |
onComplete(Runnable onCompletion)
Register a callback to be invoked when the SSE request completes.
|
ServerResponse.SseBuilder |
onError(Consumer<Throwable> onError)
Register a callback to be invoked when an error occurs during SSE
processing.
|
ServerResponse.SseBuilder |
onTimeout(Runnable onTimeout)
Register a callback to be invoked when an SSE request times
out.
|
ServerResponse.SseBuilder |
retry(Duration duration)
Add an SSE "retry" line.
|
void |
send(Object object)
Sends the given object as a server-sent event.
|
void send(Object object) throws IOException
This convenience method has the same effect as
data(Object)
.
object
- the object to sendIOException
- in case of I/O errorsServerResponse.SseBuilder id(String id)
id
- the event identifierServerResponse.SseBuilder event(String eventName)
eventName
- the event nameServerResponse.SseBuilder retry(Duration duration)
duration
- the duration to convert into millisServerResponse.SseBuilder comment(String comment)
comment
- the commentvoid data(Object object) throws IOException
object
- the object to send as dataIOException
- in case of I/O errorsvoid error(Throwable t)
The throwable is dispatched back into Spring MVC, and passed to its exception handling mechanism. Since the response has been committed by this point, the response status can not change.
t
- the throwable to dispatchvoid complete()
ServerResponse.SseBuilder onTimeout(Runnable onTimeout)
onTimeout
- the callback to invoke on timeoutServerResponse.SseBuilder onError(Consumer<Throwable> onError)
onError
- the callback to invoke on errorServerResponse.SseBuilder onComplete(Runnable onCompletion)
onCompletion
- the callback to invoked on completion