简体   繁体   English

在典型的MVC应用程序中使用Akka.NET。 怎么样?

[英]Using Akka.NET in a typical MVC application. How?

I have a typical web application using Entity framework to interact with the database. 我有一个典型的Web应用程序使用Entity框架与数据库进行交互。 Here is the break down of the app. 这是应用程序的细分。

  1. Demo.Core [contains logging (nlog stuff), helper classes, system wide constants etc] Demo.Core [包含日志记录(nlog内容),帮助程序类,系统范围常量等]
  2. Demo.Entities [contains the Entity framework entities or edmx files only- no contexts] Demo.Entities [仅包含实体框架实体或edmx文件 - 无上下文]
  3. Demo.Business [ contains the data manager, the EF context, business rules using NRules, validation and stuff] Demo.Business [包含数据管理器,EF上下文,使用NRules的业务规则,验证和东西]
  4. Demo.Web [contains the MVC app that is the front end] Demo.Web [包含作为前端的MVC应用程序]

Now I want to use Akka.NET in this app. 现在我想在这个应用程序中使用Akka.NET。 I created an Engine class that encapsulates the Akka System actor and created a logging actor (Demo.Core). 我创建了一个Engine类,它封装了Akka System actor并创建了一个日志记录actor(Demo.Core)。 I'm thinking of engine as a class that has a send function which can be used system wide and the function than decides which actor is the most suitable to handle the message. 我认为引擎是一个具有send函数的类,可以在系统范围内使用,而且函数决定哪个actor最适合处理消息。

However, I'm unable to decide how to manage the Data context and entity classes in terms of akka. 但是,我无法决定如何根据akka管理数据上下文和实体类。

  1. Should I have separate Actor for retrieving each type of entity? 我应该有单独的Actor来检索每种类型的实体吗? or one Actor for retrieving all entities? 或者一个Actor用于检索所有实体?
  2. Should I have multiple actors with different contexts for different roles, for instance DBReaderActor & DBWriterActor or a single actor that has the contextto the database? 我是否应该为具有不同角色的不同上下文设置多个actor,例如DBReaderActor和DBWriterActor或具有数据库上下文的单个actor?
  3. Is it okay to have an engine that has a single send function as mentioned above or each class should call the appropriate actor itself? 如上所述,拥有单个发送功能的引擎是否可以,或者每个类应该调用适当的actor本身?
  4. Can actors of a system be in multiple assemblies? 系统的参与者可以在多个程序集中吗? like Demo.Core & Demo.Business? 喜欢Demo.Core&Demo.Business?
  5. If I run two instances of Demo.Web one on IIS and one on WebDev would they have 2 separate actor systems or a single actor system (they both use the identical code base)? 如果我在IIS上运行两个Demo.Web实例,在WebDev上运行一个实例,它们将有2个独立的actor系统或单个actor系统(它们都使用相同的代码库)?

    I'm a newbie in Akka.NET so please don't assume things when answering 我是Akka.NET的新手,所以在回答时请不要假设

So the answer to the majority of these questions tends to be "it depends", it depends heavily on your architecture and application requirements but I'll try and break it down here. 因此,大多数问题的答案往往是“它取决于”,它在很大程度上取决于您的架构和应用程序要求,但我会尝试在此处分解。

1) It depends on how frequently you retrieve entities. 1)这取决于您检索实体的频率。 Since actors process messages one at a time, if you've got lots of requests per entity then you might end up with long requests to retrieve data if the queue of messages is too long. 由于参与者一次处理一个消息,如果每个实体有大量请求,那么如果消息队列太长,您可能会遇到长时间检索数据的请求。 As Akka.Net is a tool for building concurrent applications, it's usual to split work down into the smallest unit of work, so you can easily distribute the work. 由于Akka.Net是用于构建并发应用程序的工具,因此通常将工作分成最小的工作单元,这样您就可以轻松地分配工作。

2) It depends on whether your application is constrained by reads or writes and whether you have strong requirements on ordering of reads and writes. 2)这取决于您的应用程序是否受读取或写入限制,以及您是否对读取和写入顺序有强烈要求。 Messages are processed serially, so if you have lots of writes going to a database through an actor responsible for both reading and writing, then reads may take some time to be processed. 消息是按顺序处理的,因此如果有大量写入通过负责读取和写入的actor进入数据库,则读取可能需要一些时间才能处理。 Similarly if you have hard constraints that a certain read must happen before a given write then you'll want the reads and writes to exist in the same queue. 类似地,如果您有硬限制,某个读取必须在给定的写入之前发生,那么您将希望读取和写入存在于同一队列中。

3) Actors are addressed by a URI, so it's possible to retrieve them through a well-known URI and the use of ActorSelection on the ActorSystem instance. 3)Actor由URI寻址,因此可以通过众所周知的URI和ActorSystem实例上的ActorSelection来检索它们。 There is usually no need to create a custom function to Send to an actor. 通常不需要创建自定义函数来发送给actor。 Instead create common functions to retrieve actor URIs based on the URI parts. 而是创建公共函数以基于URI部分检索actor URI。

4) Yes actors can exist in multiple assemblies, you just need to ensure they inherit from one of the actor types, typically ReceiveActor or UntypedActor. 4)是的actor可以存在于多个程序集中,您只需要确保它们从一个actor类型继承,通常是ReceiveActor或UntypedActor。

5) They'd have 2 separate actor systems but it's possible to join them through either Akka.Remote or Akka.Cluster. 5)他们有2个独立的演员系统,但可以通过Akka.Remote或Akka.Cluster加入它们。 Actor systems are usually long running processes though and so are frequently left to run on servers dedicated to running the actor system and front end nodes running the web server, simply join the system and push messages into it or pull data out of it. Actor系统通常是长时间运行的进程,因此经常在专用于运行actor系统的服务器和运行Web服务器的前端节点上运行,只需加入系统并将消息推入其中或从中提取数据。

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

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