Akka.net ActorSystem.AwaitTermination 没有消息发送时触发 DeathWatch 通知

Akka.net ActorSystem.AwaitTermination triggers DeathWatchNotification when no messages are sent

此消息以最简单的 Akka.net 示例应用程序写入控制台。

[INFO][11/3/2015 7:21:06 PM][Thread 0008][akka://TestActorSystem/user] Message DeathWatchNotification from akka://TestActorSystem/user to akka://TestActorSystem/user was not delivered. 1 dead letters encountered.

这是非常简单的代码,您所做的只是创建一个演员,但您永远不会发送任何消息。

using System;
using Akka.Actor;
namespace AkkaNetTest {
    class Program {
        static void Main(string[] args) {
            ActorSystem testActorSystem = ActorSystem.Create("TestActorSystem");
            Console.WriteLine("Actor system 'TestActorSystem' created");
            IActorRef testActor = testActorSystem.ActorOf<TestActor>("Test");
            Console.WriteLine("Press a key to shutdown the 'TestActorSystem' actor system");
            Console.ReadKey();
            Console.WriteLine("Attempting to shutdown the actor system");
            testActorSystem.Shutdown();
            Console.WriteLine("Waiting for the actor system to terminate.");
            testActorSystem.AwaitTermination();
            Console.WriteLine("Actor system shutdown, press any key to exit");
            Console.ReadKey(); 
        }
    }
    public class TestActor : ReceiveActor { }
}

我运行所在的环境是:

  • Windows 10 RTM build 10240
  • Visual Studio 2013 Update 5
  • Akka.Net via NeGet 1.0.4.12
  • Target framework .NET 4.5
  • Install framework .NET 4.5.2
  • Console Application
  • Any CPU

当您 运行 这个简单的应用程序时,上面的 Akka.net 输出会在 ActorSystem.AwaitTermination() 调用后立即出现。

它出现在我尝试创建的所有 Akka.net 应用程序中,并且我能够在这个简单的应用程序中重现它。因此,如果我发送消息或不发送消息,它总是会发生。如果您注释掉 IActorRef 行,那么您将不会收到消息,因为没有创建演员。

这无法解释为什么会发生这种情况。如果有人可以帮助解释为什么会发生这种情况,以及即使在没有发送过任何消息的情况下如何防止这种情况发生,我将不胜感激。

您正在呼叫 testActorSystem.Shutdown(); - 这将关闭 ActorSystem。这会杀死所有参与者,包括内置系统参与者 - 因此 DeathWatchNotifications 作为关闭和清理过程的一部分被触发。在这种情况下,您看到的消息是 /user guardian actor 正在关闭自身,因为它正在关闭,所以没有被传送。

如文档所述,这不是错误,无需担心:http://getakka.net/docs/concepts/message-delivery-reliability#dead-letters-which-are-usually-not-worrisome

为防止出现此错误,您必须执行以下操作,直到他们将默认日志记录级别修复为警告。

将以下内容添加到您的应用配置中,INFO 日志消息将会消失。 @Aaronontheweb 在错误报告中指出此消息是 "nothing to be worried about".

<configuration>
  <configSections>
    <section name="akka"
             type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
  </configSections>
  <akka>
    <hocon>
      <![CDATA[
          akka {
            loglevel = WARNING
          }
      ]]>
    </hocon>
  </akka>
</configuration>