public class SseEmitter extends ResponseBodyEmitter
ResponseBodyEmitter
for sending
Server-Sent Events.Modifier and Type | Class and Description |
---|---|
static interface |
SseEmitter.SseEventBuilder
A builder for an SSE event.
|
private static class |
SseEmitter.SseEventBuilderImpl
Default implementation of SseEventBuilder.
|
ResponseBodyEmitter.DataWithMediaType, ResponseBodyEmitter.Handler
Modifier and Type | Field and Description |
---|---|
(package private) static MediaType |
TEXT_PLAIN |
Constructor and Description |
---|
SseEmitter() |
Modifier and Type | Method and Description |
---|---|
static SseEmitter.SseEventBuilder |
event() |
protected void |
extendResponse(ServerHttpResponse outputMessage)
Invoked after the response is updated with the status code and headers,
if the ResponseBodyEmitter is wrapped in a ResponseEntity, but before the
response is committed, i.e.
|
void |
send(java.lang.Object object)
Send the object formatted as a single SSE "data" line.
|
void |
send(java.lang.Object object,
MediaType mediaType)
Send the object formatted as a single SSE "data" line.
|
void |
send(SseEmitter.SseEventBuilder builder)
Send an SSE event prepared with the given builder.
|
complete, completeWithError, getTimeout, initialize, onCompletion, onTimeout
static final MediaType TEXT_PLAIN
protected void extendResponse(ServerHttpResponse outputMessage)
ResponseBodyEmitter
The default implementation is empty.
extendResponse
in class ResponseBodyEmitter
public void send(java.lang.Object object) throws java.io.IOException
// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject));
send
in class ResponseBodyEmitter
object
- the object to writejava.io.IOException
- raised when an I/O error occursjava.lang.IllegalStateException
- wraps any other errorspublic void send(java.lang.Object object, MediaType mediaType) throws java.io.IOException
// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject, MediaType.APPLICATION_JSON));
send
in class ResponseBodyEmitter
object
- the object to writemediaType
- a MediaType hint for selecting an HttpMessageConverterjava.io.IOException
- raised when an I/O error occurspublic void send(SseEmitter.SseEventBuilder builder) throws java.io.IOException
// static import of SseEmitter SseEmitter emitter = new SseEmitter(); emitter.send(event().name("update").id("1").data(myObject));
builder
- a builder for an SSE formatted event.java.io.IOException
- raised when an I/O error occurspublic static SseEmitter.SseEventBuilder event()