简体   繁体   English

并发性:使用Play Framework / Akka设计REST API

[英]Concurrency : Designing a REST API using Play Framework/Akka

I m relatively new to Play framework. 我对Play框架比较陌生。 I'm trying to design a "Test/Quiz/Exam" app. 我正在尝试设计一个“测试/测验/考试”应用程序。 It mostly consist of few CRUD operations on multiple tables (Right Now). 它主要由对多个表的少量CRUD操作组成(立即)。 Its has a REST based Back end -- > AngularJS frontend. 它具有基于REST的后端-> AngularJS前端。

Lets say for the GET request of format /users/{id} the following code is mapped 假设对于格式为/ users / {id}的GET请求,以下代码已映射

public Result getUser(Long id)  {
    // Get Info from DB using Spring Data JPA and return result.
}

Now as I came across Akka Actor model, is it better to re-write the getUser function such that it delegates the work to an Actor which retrieves the data from the DB and returns it. 现在,当我遇到Akka Actor模型时,最好重写getUser函数,以便将工作委托给Actor,后者从DB中检索数据并返回。 Should i follow actor model for rest of the CRUD operations too ?. 对于其余的CRUD操作,我也应该遵循actor模型吗? Or is it an overkill to user Akka here (assuming the Play takes care of the concurrency for each request). 还是对用户Akka来说是一个过大的选择(假设Play负责每个请求的并发性)。 FYI I just started looking into Akka. 仅供参考,我刚刚开始研究Akka。

Design tips would be appreciated. 设计技巧将不胜感激。

It's overkill to use Akka here, because Play handles the inter-request concurrency and from your description of the problem it doesn't appear that you have any intra-request concurrency (which is where you'd use Akka, eg if you were making a thousand independent database queries then you could distribute these across a dozen actors or something along those lines). 在这里使用Akka实在是太过分了,因为Play会处理请求间并发,并且从您对问题的描述来看,您似乎没有任何请求内并发(这就是您使用Akka的地方,例如,如果您正在一千个独立的数据库查询,然后您就可以将它们分布在十几个参与者或类似的对象之间。 If you just want to make the Play actions asynchronous then see the JavaAsync documentation. 如果您只想使Play操作异步进行,请参阅JavaAsync文档。

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

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