Like in large organization actors form hierarchies. In my previous Actors post we discussed a bit on hierarchy. The Figure 1 shows the tree hierarchy structure while creating actors. Therefore each actor will always contain a parent actor, which is a supervised actor. We will take supervise actor in a separate post and discuss.
The main objective of this above tree hierarchy structure is to make small process components (micro level services). It has a big benefit of handling the failures in their parent level. Therefore it will allow us to keep our application alive.
The top-level actors are lived within the Error Kernel layer. So until it reaches to the top-level actors the fully scaled application won’t shutdown. This pattern is extracted from Erlang Theories.
Through out our blog series we’ve seen several time and discussed about accessing the actors. Lets look in to deep on Actor selection and the path.
Actor System occupies a main role in Akka application.
Everything is build up from ActorSystem. In Figure 2 shows the thing that ActorSystem is focusing.
Dead Letter Office : It’s an another Actor that lives within ActorSystem. This actor is created by Akka. In case if actors find any communication problems (A actors is not exist or not running), the message will ends up with Dead Letter Office.
System Guardian Actor : These actors are not created by us. It will be created by Akka internally to coordinate the whole system.
User Guardian Actor : We are now concern about actors. They can’t independently stay in Akka application. It will exist under a parent. Hence, User Guardian Actor is the parent of all Actors that we create from ActorSystem (using ActorSystem.actorOf() method)
Event Stream : This component lives on ActorSystem and it’s mainly used to log the messages.
Scheduler : When ever we create a scheduler that will created on ActorSytem.
Setting : All the setting and configuration for the System can be accessed using ActorSystem.
All these guardian actors are living to build the resiliency in the system.
When we are creating the “family” ActorSystem the User Guardian Actor is created.
So if we need to travel through the tree to access the Actor, the parent-child relationship should be placed in the path.
The URL pattern is standard through the Akka application. For an example we are creating “mother” Actor, so the expaned URL path will be,
If we are dealing with only single ActorSystem (lives on only in one machine), the location and port information won’t be useful. But when we are creating Clusters in Akka, machine information is essential. To access a remote machine and remote Actors the URL needs to be included with HOST, PORT.
Now lets take the family members example again and expand it (Figure 3).
To implement in much more nicely we will use HOCON (Human-Optimized Config Object Notation) configuration specification. So lets add our entire actor configuration in
It’s very challenging task to test the micro level services. But Akka provides us to log all the flow by adding the following configuration,
Therefore when we run it will log all the operations:
In this example familyMembers is a supervisor to all the child nodes/members. Since now actor configurations are provided in the conf file and to get the conf details the implementation will be like this:
When comparing to the previous sample code the additional actors are the supervised actor and several child actors.
In this example code I have used two ways to select the actors.
- Storing the actorRef object
I hope now you would have got a pretty good idea about the ActorSystem, actor hierarchy and the structure. In our next blog we will see how the fault tolerance is handled and implemented.
To download the sample code : Download