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

1

7

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 ?

Romo answered 5/8, 2015 at 7:32 Comment(1)
I apologize. The console actor was instantiated with different props.Romo
C
9

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));
    }
}
Concerted answered 5/8, 2015 at 17:24 Comment(1)
Thank you. Didnt know ReceiveAny() existed.Romo

© 2022 - 2024 — McMap. All rights reserved.