Restlet流数据 [英] Restlet streaming data

查看:101
本文介绍了Restlet流数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要执行的任务是从设备读取数据并使其通过Web服务可用.每秒读取4次数据.我希望Web客户端具有开放的HTTP连接,并使用分块传输来获取设备读数作为流. a>只要客户端保持连接打开.

I have this task that I'm undertaking where I would be reading data from a device and make it available over a web service. The data is read 4 times a second. I want the web clients to be have an open HTTP connection and get the device readings as a stream using chunked transfer as long as the client keeps the connection open.

作为概念证明,我想从一个不断生成随机数(每秒4次)的服务开始,将其包装在json中并将其流式传输到客户端.我正在尝试基于 twitter流式api对其进行松散建模.

As a proof of concept, I want to start with a service that constantly generates a random number, 4 times a second, wraps it in json and stream that to clients. I'm trying to model it loosely based on twitter streaming api.

我正在使用restlet 2.1.2创建该Web服务,但是我不确定应该使用哪个表示形式来实现此目的.我尝试搜索此内容,但未发现任何有用的信息.有人可以针对我应该使用的东西以及一些示例,向我指出正确的方向.

I'm using restlet 2.1.2 to create that webservice but I'm not sure which Representation I should be using to achieve this. I tried searching for this but didn't find anything useful. Could someone point me in the right direction as to what I should be using and maybe some examples, perhaps.

谢谢

推荐答案

要实现您要执行的操作,我将使用回答您的其他问题),但是我很确定您的设计方向错误.

To achieve what you are trying to do, I'd use the WriterRepresentation (but see my answer to your other question), but I'm quite sure that you are going in the wrong architectural direction.

实际上是您链接的文档中的下图

Indeed the following image from the documentation you linked

展示了Twitter流api也不打算由用户而是由后台进程连接,这些后台进程在HTTP可以访问的商店中下载消息.用户仅轮询HTTP服务器,该HTTP服务器从存储中读取消息并将其发送回客户端.

shows how even the Twitter streaming api is not intended to be connected by users, but by background processes that download messages in a store accessible by the HTTP. Users poll only the HTTP server, that reads the messages from the store and sends the back to the clients.

作为断开连接的协议,HTTP 启用了大规模的可伸缩性,否则将无法实现.如果每个客户端建立由专用服务器线程支持的持久TCP 连接,您将迅速耗尽服务器资源!此外,用户代理和服务器之间的任何HTTP代理都可能导致意外行为.

As a disconnected protocol, HTTP enable massive scalability that would not be possible otherwise. If each client establishes a persistent TCP connection backed by a dedicated server thread, you will rapidly exaust server resources! Moreover any HTTP proxy between the User Agent and the server could cause unexpected behaviours.

因此,如果您绑定到HTTP协议,则用户代理应进行轮询.您可以使用最后修改/ If-Modified-Since Etag /

Thus, if you are bound to the HTTP protocol, the User Agent should poll. You can reduce the network load with headers like Last-Modified/If-Modified-Since or Etag/If-None-Match.

但是,如果可以采用其他协议,我强烈建议尝试通过连接的TCP协议尝试服务总线.

However, if you can adopt a different protocol, I strongly suggest to try a service bus over a connected TCP protocol.

这篇关于Restlet流数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆