简体   繁体   English

用于创建异步流API的框架

[英]Frameworks for creating asynchronous streaming API

The architecture of our application consists of several modules. 我们的应用程序的体系结构包含几个模块。 The modules can run as a single process, or separately on a different server. 这些模块可以作为单个进程运行,也可以在其他服务器上分别运行。 We are using REST for the interaction between modules when they are on different servers. 当模块位于不同服务器上时,我们正在使用REST进行模块之间的交互。 Now we need to process streaming data between modules. 现在,我们需要处理模块之间的流数据。 One module sends a request -- another module asynchronously sends back chunks of data (objects). 一个模块发送请求-另一个模块异步发送回数据块(对象)。 We have tried to use KryoNet and Apache Mina. 我们试图使用KryoNet和Apache Mina。 We have selected the last one and in general everything works. 我们选择了最后一个,总的来说一切正常。 But the solution has several problems, and there is a feeling that we reinvent the wheel. 但是该解决方案存在几个问题,并且有一种我们重新发明轮子的感觉。

Maybe there is ready framework for creating asynchronous API to transmit streaming data and that support several transports and built-in serialization: 也许有一个现成的框架可用于创建异步API来传输流数据,并支持多种传输和内置序列化:

  • local -- when the modules / services interact within a single process 本地-模块/服务在单个流程中交互时
  • netty or analog -- when the modules interact with each other on different machines netty或类比-当模块在不同计算机上相互交互时
  • REST -- to interact with modules over HTTP REST-通过HTTP与模块交互

Something like elasticsearch Java API -- all operations can be performed asynchronously, through the network, locally or via REST. 类似Elasticsearch Java API之类的东西-所有操作都可以通过网络,本地或REST异步执行。 Is there a ready-made frameworks for the creation such API? 是否存在用于创建此类API的现成框架?

We are using Scala 2.10 and Java. 我们正在使用Scala 2.10和Java。

How about finagle? 怎么样? https://github.com/twitter/finagle https://github.com/twitter/finagle

It doesn't cover all your needs out of the box, but it's a very nice and extensible framework and might provide a good base to build upon. 它不能立即满足您的所有需求,但是它是一个非常不错的可扩展框架,并且可以为您提供良好的基础。

And you can see an example of doing a streaming server using finagle: https://github.com/twitter/finagle/blob/master/finagle-example/src/main/scala/com/twitter/finagle/example/stream/StreamServer.scala 您会看到一个使用finagle制作流服务器的示例: https : //github.com/twitter/finagle/blob/master/finagle-example/src/main/scala/com/twitter/finagle/example/stream/ StreamServer.scala

您当然也应该看看Akka IO: http : //doc.akka.io/docs/akka/snapshot/scala/io.html

I would suggest Scramjet . 我建议使用超燃冲压发动机 It will work with your local and analog cases, but it will simply shine when given a task with multiple REST API's in the pipeline - in this case it scales logarithmic while other streaming systems scale exponentially (!). 它可以在您的本地和模拟情况下使用,但是当在管道中执行具有多个REST API的任务时,它只会闪耀-在这种情况下,它可以对数扩展,而其他流系统则按指数比例扩展(!)。 Here's a benchmark scramjet-benchmark on GitHub 这是GitHub上的基准scramjet基准测试

It can be programmed with a chain of simple lambdas and is based on node.js with all the plethora of asynchronous modules you'll be able to run all your REST services in a single line (I suggest you tried request-promise). 它可以使用一系列简单的lambda进行编程,并且基于具有大量异步模块的node.js,您将能够在同一行中运行所有REST服务(我建议您尝试请求承诺)。 A simple case looks like this: 一个简单的情况如下所示:

const scramjet = require("scramjet");
const request = require("request-promise");

process.stdin.pipe(new scramjet.StringStream())
    .split("\r?\n")
    .map((uri) => request.get("https://example.com/" + uri))
    .filter((data) => data.status === 200 && data.articleUrl)
    .map((data) => request.get("http://somesite.org/" + data.articleUrl)
    .accumulate((data) => database.put(data.key, data))
    .then(() => console.log('finished'))

And that's it for a software that calls two API's and writes the results to database. 这就是用于调用两个API并将结果写入数据库的软件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM