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.
|
| 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(Object object)
Send the object formatted as a single SSE "data" line.
|
void |
send(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, onCompletion, onTimeoutprotected void extendResponse(ServerHttpResponse outputMessage)
ResponseBodyEmitterThe default implementation is empty.
extendResponse in class ResponseBodyEmitterpublic void send(Object object) throws IOException
// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject));
send in class ResponseBodyEmitterobject - the object to writeIOException - raised when an I/O error occursIllegalStateException - wraps any other errorspublic void send(Object object, MediaType mediaType) throws IOException
// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject, MediaType.APPLICATION_JSON));
send in class ResponseBodyEmitterobject - the object to writemediaType - a MediaType hint for selecting an HttpMessageConverterIOException - raised when an I/O error occurspublic void send(SseEmitter.SseEventBuilder builder) throws 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.IOException - raised when an I/O error occurspublic static SseEmitter.SseEventBuilder event()