Only 3 fundamental properties of an actor:
- Send messages
- Create others actors
- Switch behavior
Actors also have globally unique addrses within their ActorSystem
.
Read "What is An Actor?" here.
IActorRef
s are a handle to an actor. You send messages to it, and the ActorSystem
is responsible for delivering them (often over the network / between processes).
var props = Props.Create(() => new MyActorClass(actorDependency));
MyActorSystem = ActorSystem.Create("MyActorSystem");
var dependency = "some string my actor depends on";
var myActor = MyActorSystem.ActorOf(Props.Create(() => new MyActorClass(dependency)), "MyActor");
// create child
Context.ActorOf(Props.Create(() => new MyChildActorClass()), "childActorName");
// look up child actor
Context.Child("childActorName");
Messages are just POCOs. Nothing scary here.
// just Tell the message to the actor
myActor.Tell(new StartProcessing());
All actors have a parent (who supervises them), and all actors can be a parent.
Learn more about hierarchies here.
ActorSelection
is the practice of looking up an actor by its ActorPath
.
Generally, you want to favor IActorRef
s over ActorSelection
s. Learn more here.
All actors have a lifecycle, and you can tap into it.
- Starting
- Receiving
- Stopping
- Terminated
- Restarting
PreStart
PostStop
PreRestart
PostRestart
Nice cheatsheet. I guess a little about switchable behavior can be written like
Become()
method.