Using Akka.NET in a typical MVC application. How?

I have a typical web application using the Entity framework to interact with a database. Here is a breakdown of the application.

  • Demo.Core [contains entries (nlog stuff), auxiliary classes, system wide constants, etc.]
  • Demo.Entities [contains Entity framework entities or edmx files only - no contexts]
  • Demo.Business [contains data manager, EF context, business rules using NRules, validation, etc.]
  • Demo.Web [contains an MVC application that is an interface]

Now I want to use Akka.NET in this application. I created an Engine class that encapsulates an Akka system actor and created a registration member (Demo.Core). Im thinks of the engine as a class that has a send function that can be used in the system system and function, which decides which actor is most suitable for processing the message.

However, I cannot decide how to manage data classes and object classes from akka's point of view.

  • Do I have to have a separate Actor to get each type of entity? or one actor to extract all objects?
  • Should I have several participants with different contexts for different roles, for example, DBReaderActor and DBWriterActor or one actor who has a context for the database?
  • Is it possible to have an engine that has one send function like the one mentioned above, or should each class name the corresponding actor itself?
  • Can members of the system be in multiple assemblies? How is Demo.Core & Demo.Business?
  • If I run two instances of Demo.Web, one on IIS and one on WebDev, will they have two separate actor systems or one actor system (they both use the same code base)?

    I am new to Akka.NET, so please do not take things when answering

+4
source share
1 answer

So the answer to most of these questions tends to be โ€œit dependsโ€, it pretty much depends on your requirements for architecture and applications, but I will try to break it here.

1) It depends on how often you get objects. Since participants process messages one at a time, if you have a lot of requests for an object, then you can receive long requests for data if the message queue is too long. Since Akka.Net is a tool for creating concurrent applications, it usually breaks up work into the smallest unit of work, so you can easily distribute work.

2) It depends on whether your application is limited to reading or writing, and whether you have strong requirements for reading and writing. Messages are processed sequentially, so if you have many records entering the database through the actor responsible for reading and writing, then reading may take some time to process. Similarly, if you have strict restrictions that a specific read must occur before a given write, you need the read and write to exist in the same queue.

3) Actors are addressed using a URI, so you can get them through a well-known URI and using ActorSelection in an instance of ActorSystem. Usually there is no need to create a custom function to send to the actor. Instead, create generic functions to retrieve custom URIs based on parts of the URI.

4) Yes, actors can exist in several assemblies, you just need to make sure that they inherit from one of the types of actors, usually ReceiveActor or UntypedActor.

5) They will have two separate acting systems, but it is possible to join them through Akka.Remote or Akka.Cluster. The actor of the system, as a rule, is long processes, although they are often left to run on servers designed to run the actor system and the front nodes running on the web server, simply join the system and insert messages into it or pull data from it.

+3
source

All Articles