收藏
回答

RequestTask.onChunkReceived数据丢失(本地丢失少,线上丢失过多)?

springboot后端SSE流式接口看日志是返回完整的markdow格式,但是RequestTask.onChunkReceived出现数据部分丢失(本地的微信开发工具调试少有丢失,线上版本丢失很严重,用的都是正式版本的后端接口,导致markdown格式化成文本出错,前端内容出现错位及阅读性障碍。麻烦告知解决方案,本地与线上数据丢失偏移过大。

最后一次编辑于  06-25
回答关注问题邀请回答
收藏

3 个回答

  • 艺术家小锃子
    艺术家小锃子
    06-26

    顶一下

    06-26
    有用 1
    回复
  • 如日
    如日
    08-27
    可以考虑一下,真机连接的后端的相关sse接口有没有禁用nginx缓存,需要手动禁用缓存。可以参考:
    # 设置 Nginx 不对 SSE 响应进行缓冲,直接透传给客户端
    proxy_buffering off;
    
    
    # 设置代理读取服务器响应的超时时间
    proxy_read_timeout 24h;
    
    
    # 设置客户端连接的超时时间
    proxy_connect_timeout 1h;
    
    
    # 设置 HTTP 版本,SSE 需要 HTTP/1.1
    proxy_http_version 1.1;
    
    
    # 保持连接活性,不发送连接关闭的信号
    proxy_set_header Connection '';
    
    
    # 配置代理传递的头部,确保 Host 头部正确传递
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    
    
    # 设置代理的响应头部,保持传输编码为 chunked
    proxy_set_header X-Accel-Buffering no;
    
    
    # 设置流式响应头
    proxy_set_header Accept "text/event-stream";
    proxy_set_header Cache-Control "no-cache";
    
    
    # 禁用压缩
    proxy_set_header Accept-Encoding "";
    
    
    # 设置跨域资源共享 (CORS)
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With,Content-Type' always;
    
    


    08-27
    有用
    回复
  • DQ
    DQ
    07-07

    我们也是,偶尔丢字,后端sse数据块正常. 可能是小程序分片有截断

    07-07
    有用
    回复
登录 后发表内容