Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring SSE用于长时间运行过程_Spring_Angular_Spring Boot_Websocket_Server Sent Events - Fatal编程技术网

Spring SSE用于长时间运行过程

Spring SSE用于长时间运行过程,spring,angular,spring-boot,websocket,server-sent-events,Spring,Angular,Spring Boot,Websocket,Server Sent Events,我有一个使用Spring开发的RESTAPI,Angular 5前端使用它。我的服务大约需要5分钟才能完成,我的负载平衡器会断开来自浏览器的连接 我们无法实现WebSocket,因为ws协议被代理阻止。我们希望在服务器端实现Spring SSE,在angular上作为客户端实现EventSource 我们有以下客户端和服务器代码 当异步处理完成并且服务器尝试发送响应时,我们得到以下错误。我无法理解这是Tomcat断开连接还是浏览器 17:32:40.101 [GithubLookup-1] IN

我有一个使用Spring开发的RESTAPI,Angular 5前端使用它。我的服务大约需要5分钟才能完成,我的负载平衡器会断开来自浏览器的连接

我们无法实现WebSocket,因为ws协议被代理阻止。我们希望在服务器端实现Spring SSE,在angular上作为客户端实现EventSource

我们有以下客户端和服务器代码

当异步处理完成并且服务器尝试发送响应时,我们得到以下错误。我无法理解这是Tomcat断开连接还是浏览器

17:32:40.101 [GithubLookup-1] INFO  o.a.coyote.http11.Http11Processor - An error occurred in processing while on a non-container thread. The connection will be closed immediately
java.io.IOException: An established connection was aborted by the software in your host machine
    at sun.nio.ch.SocketDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
代码


连接保持活动状态不工作,因为连接上没有活动

我的负载平衡器正在终止连接


现在可以通过每30秒发送一次连接上的假数据并保持连接的活动状态来解决此问题。

因此,负载平衡器可能会再次中止您的连接,因为您没有向它发送任何内容?您可以在浏览器开发工具中查看此连接的情况。或者,您可以尝试在作业运行期间重复从服务器发送一些假数据,这样连接就不会关闭。谢谢,现在我每30秒发送一些假数据,连接不会关闭。
public SseEmitter doSomething() {
      final SseEmitter emitter = new SseEmitter(600000L);
      CompletableFuture<Response> res = ... some Service call which takes 5 min, but annotated with @Async
      completableFuture.whenComplete((res, ex) -> {
        emitter.send(res);
        emitter.complete();
      }
      emitter.send("Running"); // Some fake status to let client know it is accepted and running
      return emitter;
    }
  let eventSource = new EventSource(url, {
      xhrHeaders: {
          'Content-Type': 'text/event-stream'
      }
  });
  eventSource.onmessage = (event) => {
      console.log('Received event: ', event);
  };