如何在Akka中接收任何类型的消息.净接收Actor

本文关键字:消息 Actor 类型 任何 Akka | 更新日期: 2023-09-27 18:06:37

我正在尝试为我所有的演员实现某种类型的控制台作家。下面是我的代码:

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

问题是,不知何故演员没有收到任何消息。我从控制台得到了这个日志:

[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.    

哪里出错了

如何在Akka中接收任何类型的消息.净接收Actor

听起来你已经解决了DeadLetters的问题。要回答您最初的问题:要接收ReceiveActor中的任何消息,请使用ReceiveAny (docs),如下所示:

class ConsoleWriterActor : ReceiveActor
{
    public ConsoleWriterActor()
    {
        ReceiveAny(o => Console.WriteLine("Received object: " + o));
    }
}