akka.net - Finding a previously persisted Akka actor with an indirect reference -


there quite few places in system building in there multiple ways reach same actor. instance, if have persistent car actor, use vin or registration plate.

as need single "true name" use actor name/persistence id when recreating actor, these "lookups/references" actors, named after key, persisting id of actor reference.

does seem right way it? seems lot of actors aren't actors, proxies.

edited update answer.

it sounds have repository contains collection of cars, , each car can have vin or reg number (or serial number, or chassis number... things uniquely identify car).

id    |  vin  |  reg car1  |  abc  |  123 car2  |  def  |  456 

we have persistent caractor encapsulates state , logic car.

public class caractor : persistentreceiveactor {     string _id;     public override string persistenceid { { return _id; } }      public caractor(string id)     {         _id = id;     }      public static props props(string id)     {         return akka.actor.props.create(() => new caractor(id));     }      } 

as need single "true name" use actor name/persistence id when recreating actor, these "lookups/references" actors, named after key, persisting id of actor reference.

does seem right way it? seems lot of actors aren't actors, proxies.

to simplify things, define message encapsulates various id numbers car can identified with. message can passed our actor system processing.

public class carcommand {     public string vin { get; private set; }     public string reg { get; private set; } } 

best practice have supervisor or router actor responsible domain of entities , elects represent each entity own actor. supervisor can receive carcommand message, id of car vin or reg, , find/create child actor process message.

public class carsupervisor : receiveactor {     //in reality repository e.g. db context...     //be better if handled in actor actor     //has access     readonly ienumerable<cars> _cars;      public carsupervisor(ienumerable<cars> cars)     {         _cars = cars;         receive<carcommand>(command =>          {             //find car vin or reg or other variable             var car = _cars.first(c => c.vin == command.vin);             //see if child actors have been created car instance             var child = context.child(car.id);             //if don't have incarnation yet, create 1             if (equals(child, actorrefs.nobody))                 child = context.actorof(caractor.props(car.id), car.id));             //tell child process message             child.forward(command);         });     }       } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -