使用Spring,休息和角度JS输出连续轮询 [英] Continuous polling of output using spring ,rest and angular js
问题描述
我的工作其中的前端在角的js和Spring MVC和从RESTful Web服务所消耗的数据开发的Web应用程序。
有一个场景,其中REST Web服务的日志文件上执行tail命令。
现在,这个输出应该对这个UI.Any指针进行流式处理将是有益的。
I am working on a web application the frontend of which is developed in angular js and spring mvc and which consumes the data from a RESTful webservice. There is a scenario wherein the REST webservice executes a tail command on a log file. Now this output should be streamed on the UI.Any pointers on this would be helpful.
推荐答案
解决方案1
也许你想看看到的WebSockets。我们的想法是,你打开信息交换服务器和客户机之间的连接contineous。这可以用于从服务器接收日志文件更新
Maybe you want to take a look into WebSockets. The idea is, that you open a contineous connection between server and client for information exchange. This could be used for receiving log file updates from server.
该情况可能是这样的:
- 用户进入日志查看页面,从而为订阅获取日志文件更新
- 在服务器端code,其中执行tail命令,更新发送到所有的订阅
- 用户收到新的日志内容
- > 春天的WebSockets < -
-> Spring Websockets <-
解决方案2
普通投票另一种解决方案是使用JavaScript计时器功能重复请求你的日志文件。事情是这样的:
Another solution of plain polling would be to use a javascript timer function for repeating requests to your log file. Something like this:
setTimeout(function(){ queryLogFile() }, 1000);
然而,这将导致大量的请求,所以也许你应该使用某种缓存机制您的日志文件。
However, this will result in a high amount of requests, so maybe you should use some kind of caching mechanism for your log file.
这篇关于使用Spring,休息和角度JS输出连续轮询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!