在grails中实现SseEmitter

时间:2019-06-27 16:28:50

标签: java spring grails server-sent-events

我尝试在实现API的grails中实现SseEmitter,并在前端使用angular。

def realtime() {
        Long timeoutTime;
        use(groovy.time.TimeCategory) {
            timeoutTime = Instant.now().toEpochMilli() + 5.minutes.toMilliseconds()
        }
        log.info("timeout time ${timeoutTime}");
        final SseEmitter emitter = new SseEmitter();
        emitter.onTimeout(new Runnable() {
            @Override
            void run() {
                emitter.complete();
            }
        });
        response.setContentType("text/event-stream, charset=UTF-8")
        render emitter
    }

我在grails中如上实现。连接一打开就关闭。它不成立。

0 个答案:

没有答案