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:
Solution 1
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.
The scenario could be something like this:
- User enters the log view page and thereby subscribes for getting log file updates
- In the server side code, where tail command is executed, an update is sent to all subscribers
- User receives new log content
-> Spring Websockets <-
Solution 2
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.