Tuesday, August 30, 2016

Akka.NET Tip: Name your actors

A small tip when you start using Akka.NET; name your actors. By default when you create an actorref Akka.NET will assign a name for you.

var actor=system.ActorOf(Props.Create<SampleActor>());

The problem is that when you add some logging, you’ll get errors like:

An error in occured in actor akka://test/user/$a/$a/$b

which is not very useful if you want to investigate what’s going wrong.

Remark: This is an error from inside a unit test explaining the “akka://test”.

Instead using an ActorOf overload that allows you to specify a name:

var actor=system.ActorOf(Props.Create<SampleActor>(),"sample-actor");

That’s it for today!

No comments: