小程序
小游戏
企业微信
微信支付
扫描小程序码分享
springboot后端SSE流式接口看日志是返回完整的markdow格式,但是RequestTask.onChunkReceived出现数据部分丢失(本地的微信开发工具调试少有丢失,线上版本丢失很严重,用的都是正式版本的后端接口),导致markdown格式化成文本出错,前端内容出现错位及阅读性障碍。麻烦告知解决方案,本地与线上数据丢失偏移过大。
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
顶一下
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
可以考虑一下,真机连接的后端的相关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;
我们也是,偶尔丢字,后端sse数据块正常. 可能是小程序分片有截断
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
顶一下
可以考虑一下,真机连接的后端的相关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;我们也是,偶尔丢字,后端sse数据块正常. 可能是小程序分片有截断