类 SseEmitter
- java.lang.Object
- org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
- org.springframework.web.servlet.mvc.method.annotation.SseEmitter
public class SseEmitter extends ResponseBodyEmitter
A specialization ofResponseBodyEmitter
for sending Server-Sent Events.- 从以下版本开始:
- 4.2
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
嵌套类概要
嵌套类 修饰符和类型 类 说明 static interface
SseEmitter.SseEventBuilder
A builder for an SSE event.从类继承的嵌套类/接口 org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
ResponseBodyEmitter.DataWithMediaType
构造器概要
构造器 构造器 说明 SseEmitter()
Create a new SseEmitter instance.SseEmitter(Long timeout)
Create a SseEmitter with a custom timeout value.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 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. before the response body has been written to.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.String
toString()
从类继承的方法 org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter
complete, completeWithError, getTimeout, onCompletion, onTimeout
构造器详细资料
SseEmitter
public SseEmitter()
Create a new SseEmitter instance.
SseEmitter
public SseEmitter(Long timeout)
Create a SseEmitter with a custom timeout value.By default not set in which case the default configured in the MVC Java Config or the MVC namespace is used, or if that's not set, then the timeout depends on the default of the underlying server.
- 参数:
timeout
- timeout value in milliseconds- 从以下版本开始:
- 4.2.2
方法详细资料
extendResponse
protected void extendResponse(ServerHttpResponse outputMessage)
从类复制的说明:ResponseBodyEmitter
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. before the response body has been written to.The default implementation is empty.
send
public void send(Object object) throws IOException
Send the object formatted as a single SSE "data" line. It's equivalent to:// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject));
- 覆盖:
send
在类中ResponseBodyEmitter
- 参数:
object
- the object to write- 抛出:
IOException
- raised when an I/O error occursIllegalStateException
- wraps any other errors
send
public void send(Object object, MediaType mediaType) throws IOException
Send the object formatted as a single SSE "data" line. It's equivalent to:// static import of SseEmitter.* SseEmitter emitter = new SseEmitter(); emitter.send(event().data(myObject, MediaType.APPLICATION_JSON));
- 覆盖:
send
在类中ResponseBodyEmitter
- 参数:
object
- the object to writemediaType
- a MediaType hint for selecting an HttpMessageConverter- 抛出:
IOException
- raised when an I/O error occurs
send
public void send(SseEmitter.SseEventBuilder builder) throws IOException
Send an SSE event prepared with the given builder. For example:// 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 occurs
event
public static SseEmitter.SseEventBuilder event()