1.Use REST streaming to connect products directly to nest services from cloud to cloud integrations.
2.In REST streaming, instead of returning information and close the connection, the NEST api keeps the connection open, and the REST api uses the open connection, and users can receive new state.
3.REST streaming allows for only one token(one user) per socket.
4.What is SSE(server-sent-events): a web app subscribes to a stream of updates generated by server, and whenever a new event occurs, it will send to the client.
AJAX:
- Polling: the application repeatedly polls server for data. - Long Polling: the server does not have the data available, the server holds the data until new data is made available(Hanging GET).
5.server-sent events are sent over http, but they do not require a special protocol or server implementation get working. When use server-sent requests, a server can push data to client whenever it wants, without making initial request, update can be streamed to clients as they happen. SSEs often use single un-directional channel between client and server.
Diff between SSE and Longpolling is: SSE is handled by browser and users have to listen for messages.
Server Sent Events vs Websockets:
websocket provides richer protocol to perform bi-directional, full-duplex communication, two way channel for games, messaging apps, and for cases when need real-time communications for both directions.
Server Sent Events: sometimes not needed to perform data sent from the client. Only need is to update the event from the server side.
//JavaScript API: if(!!window.eventSource) { var source = new EventSource("stream.php"); } else { //result to xhr polling; } //set up a handler for the message event source.addEventListener("message", function(e) { console.log(e.data); }, false); source.addEventListener("open", function(e) { //connection is opened }, false); source.addEventListener("error", function(e) { if(e.readyState == EventSource.CLOSED) { //connection is closed; } }, false);
Server implementation in NodeJS:
var http = require("http"); var sys = require("sys"); var fs = require("fs"); http.createServer(function(req, res) { if(req.headers.accept && req.headers.accept == "text/event-stream") { if(req.url == "/events") { sendSSE(req, res); } else { res.writeHead(200, {"Content-Type": "text/html"}); res.write(fs.readFileSync(__dirname + "/sse-node/html")); res.end(); } }).listen(8000); function.sendSSE(req, res) { res.writeHead(200, { "Content-Type":"text/event-stream", "Cache-Control": "no-cache", "Connection": "keep-alive" }); var id = (new Date()).toLocaleTimeString(); //send a SSE every 5 seconds on a single connection setInterval(function() { constrcutSSE(res, id, (new Date()).toLocaleTimeString()); } function constructSSE(res, id, data) { res.write("id: " + id + " "); res.write("data: " + data + " "); } function debugHeaders(req) { sys.put("URL: " + req.url); for(var key in req.headers) { sys.put(key + ": " + req.headers[key]); } sys.put(" "); }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/108054.html
摘要:通过状态演变,可以在状态模式中添加或删除列,以便更改应用程序部署后应捕获的业务功能。本地恢复通过扩展的调度来完成本地恢复功能,以便在恢复时考虑先前的部署位置。此功能大大提高了恢复速度。问题导读1.Flink1.7开始支持Scala哪个版本?2.Flink1.7状态演变在实际生产中有什么好处?3.支持SQL/Table API中的富集连接可以做那些事情?4.Flink1.7新增了哪些连接器Ap...
阅读 950·2023-04-26 01:47
阅读 1602·2021-11-18 13:19
阅读 1959·2019-08-30 15:44
阅读 613·2019-08-30 15:44
阅读 2275·2019-08-30 15:44
阅读 1213·2019-08-30 14:06
阅读 1404·2019-08-30 12:59
阅读 1888·2019-08-29 12:49