我尝试在实现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中如上实现。连接一打开就关闭。它不成立。