[英]SSE implementation in Spring REST
任何人都可以使用Spring Rest提供SSE(服務器發送事件)的示例嗎? 基本上我有一個請求,它的響應將由服務器以多個塊發送。 我想在Spring REST Api中使用服務器和客戶端實現,而不需要像澤西這樣的第三方休息api。
目前在Spring中沒有對SSE的任何直接支持,但看起來它現在在4.2中可用於RC2現在你可以在這里看到詳細信息https://jira.spring.io/browse/SPR-12212
這可以通過從控制器方法返回SseEmitter或ResponseBodyEmitter來實現。
@RequestMapping(value="/stream", method=RequestMethod.GET)
public ResponseBodyEmitter handle() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
// Pass the emitter to another component...
return emitter;
}
// in another thread
emitter.send(foo1);
// and again
emitter.send(foo2);
// and done
emitter.complete();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.