如何在akka.net上成为第一位或监护人?

时间:2018-06-28 16:55:05

标签: akka.net

编辑:执行摘要:漏洞是在哪里定义的“ Sys”?我在整个Internet的Akka.net代码中都看到了它,但是我的构建找不到它。我必须导入,使用,链接,做,贿赂或杀死谁或什么?

应该很容易做到。在Akka.net中采取第一步,该示例不会生成。这是从[入门示例] [1]

中复制的

[1]:https://getakka.net/articles/intro/tutorial-1.html。它不会生成,因为未定义'Sys'。在他们的网站上没有任何地方描述这个明显的基本步骤,我已经放弃了tweak-n-try。

这是所有代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyAkka
{
    class Program
    {
        public class PrintMyActorRefActor : UntypedActor
        {
            protected override void OnReceive(object message)
            {
                switch (message)
                {
                    case "printit":
                        IActorRef secondRef = Context.ActorOf(Props.Empty, "second-actor");
                        Console.WriteLine($"Second: {secondRef}");
                        break;
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var firstRef = Sys.ActorOf(Props.Create<PrintMyActorRefActor>(), "first-actor");
            Console.WriteLine($"First: {firstRef}");
            firstRef.Tell("printit", ActorRefs.NoSender);
            Console.ReadKey();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

这是您代码的有效版本:

using System;
using Akka.Actor;


namespace SysInAkkaNet
{
    class Program
    {
        public class PrintMyActorRefActor : UntypedActor
        {
            protected override void OnReceive(object message)
            {

                switch (message)
                {
                    case "printit":
                        IActorRef secondRef = Context.ActorOf(Props.Empty, "second-actor");
                        Console.WriteLine($"Second: {secondRef}");
                        break;
                }
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            using (var actorSystem = ActorSystem.Create("MyActorSystem"))
            {
                var firstRef = actorSystem.ActorOf(Props.Create<PrintMyActorRefActor>(), "first-actor");
                Console.WriteLine($"First: {firstRef}");
                firstRef.Tell("printit", ActorRefs.NoSender);
                Console.ReadKey();
            }
        }    
    }
}

您需要创建一个actor系统来放置actor。还需要添加对Akka NuGet包的引用以及相应的using Akka.Actor;语句。

我知道Akka.TestKit具有属性Sys,该属性为您提供了为给定测试创建的actor系统的引用。

除此之外,我无法回答您所引用的文档为什么显示这些示例“ Sys.ActorOf(...)”(大写S),表示它是一个(可能是-in)属性,所以我有点理解您在那里的困惑。

相关问题