What is HOCON ?
HOCON stands for Human Optimised Config Object Notation. It is a human readable format based on json.
The main use of HOCON is to manage “deployment” of Actors. By deployment we refer the instantiation of the actor based on the configuration settings. Settings include logging, location of the actor (local or remote), dispatcher type, mailbox type used by the actor, etc.
HOCON gives us the ability to change the behaviour of actors without modifying our code.
The following are the steps to add HOCON to the web.config/app.config and wire it to your code.
- Added the akka to the configuration section
<configSections>
<section name=”akka” type=”Akka.Configuration.Hocon.AkkaConfigurationSection, Akka” />
</configSections>
- Define the HOCON configuration section.
<!-- in App.config file --> <!-- add this anywhere after <configSections> --> <akka> <hocon> <![CDATA[ akka { actor { deployment { # this nested section will be accessed by akka.actor.deployment # used to configure our Actor /eventactor { } } } } ]]> </hocon> </akka>
- Wire the HOCON configuration when you instantiate an instance of the actor.
[code]
void Main(string[] args)
{
IActorRef actorRef = ActorSystem.Create("EventSystem").ActorOf(Props.Create()
= new EventHandler(), "eventactor");
}
[/code]
In this simple code snippet we have wired our HOCON configuration during the instantiation of our actor.