Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive any type of message in Akka.Net Receive Actor

Tags:

c#

akka.net

I'm trying to implement a some sort of console writer for all of my actors. Here's my code:

class ConsoleWriterActor : ReceiveActor
{
    public ConsoleWriterActor()
    {
        Receive<object>(s =>
        {
            Console.WriteLine(s.ToString());
        }
    }
}

The problem is, somehow the actor doesnt receive any messages. I got this log from console:

[INFO][8/5/2015 7:30:06 AM][Thread 0013 [akka://SPBOActorSystem/user/ConsoleWriterActor] Message StartDbOperator from akka://SPBOActorSystem/user/DbOperatorActor to akka://SPBOActorSystem/user/ConsoleWriterActor was not delivered. 1 dead letters encountered.    

What went wrong ?

like image 785
himekami Avatar asked Aug 05 '15 07:08

himekami


People also ask

How do actors work in Akka?

What is an Actor in Akka? An actor is essentially nothing more than an object that receives messages and takes actions to handle them. It is decoupled from the source of the message and its only responsibility is to properly recognize the type of message it has received and take action accordingly.

Which is one is the method in Akka actor life cycle?

1) preStart() This is overridable method, so you can override preStart() method to provide specific implementation for an Actor. It is invoked right after the starting of Actor and when an Actor is first created.


1 Answers

Sounds like you sorted out the DeadLetters question. To answer your original question: To receive any message in a ReceiveActor, use ReceiveAny(docs), like so:

class ConsoleWriterActor : ReceiveActor
{
    public ConsoleWriterActor()
    {
        ReceiveAny(o => Console.WriteLine("Received object: " + o));
    }
}
like image 112
AndrewS Avatar answered Nov 11 '22 06:11

AndrewS