如题,有了异步函数也处理了数据,但是怎么反馈给前台呢?给点思路也好
4 回答
慕斯王
TA贡献1864条经验 获得超2个赞
WebSockets can make a web page dynamic and interactive. However in many cases a combination of Ajax and HTTP streaming and/or long polling could provide a simple and effective solution.
For example news, mail, and social feeds need to update dynamically but it may be perfectly okay to do so every few minutes. Collaboration, games, and financial apps on the other hand need to be much closer to real time.
Latency alone is not a deciding factor. If the volume of messages is relatively low (e.g. monitoring network failures) HTTP streaming or polling may provide an effective solution. It is the combination of low latency, high frequency and high volume that make the best case for the use WebSocket.
看了springboot websocket文档说的,什么时候用轮询,什么时候用websocket说得很清楚,我还是乖乖的用轮询吧
墨色风雨
TA贡献1853条经验 获得超6个赞
个人觉得最简单的是用短轮询方式:
前台发送请求A,调用后台方法,后台方法启动任务后返回结果。拿到结果后,前台定期(1s)通过请求B查询后台任务是否处理完成。
添加回答
举报
0/150
提交
取消