SSE implementation in Spring REST

蹲街弑〆低调 提交于 2019-12-05 17:15:28

There isn't any direct support for SSE in Spring currently but it looks like it will be available in 4.2 which is in RC2 right now You can see the details here https://jira.spring.io/browse/SPR-12212

This works via returning an SseEmitter or a ResponseBodyEmitter from the controller methods.

@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();

You can see the Reference documentation here http://docs.spring.io/spring/docs/4.2.0.RC2/spring-framework-reference/htmlsingle/#mvc-ann-async-http-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!