akka.net - 如何在 akka.net 中获得第一或监护演员?
问题描述
编辑:执行摘要:哔哔声是在哪里定义的?我在互联网上的 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();
}
}
}
解决方案
这是您的代码的工作版本:
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();
}
}
}
}
您需要创建一个演员系统来放置您的演员。并且您需要添加对 Akka NuGet 包的引用和相应的using Akka.Actor;
语句。
我知道 Akka.TestKit 有一个 property Sys
,它为您提供对给定测试创建的 actor 系统的引用。
除此之外,我无法回答为什么您所指的文档会显示这些“Sys.ActorOf(...)”示例(带有大写 S),表明它是(可能是内置的)财产,所以我有点理解你的困惑。
推荐阅读
- html - 如何使画布标签的宽度与窗口的一半一样大?
- json - 如何从响应中获取令牌?
- c++ - 组合两个对列表
- jquery - 将两个处理程序合二为一
- android - 构建失败并出现 D8 错误
- sql-server - 从工资 > N 的多个连接表中查找前 2 个最高工资
- elasticsearch - Elasticsearch - 找到每个特征的最小值和最大值
- google-apps-script - 您无权执行该操作。请请求此项目的所有者授予您访问权限
- ubuntu - 由于访问被拒绝异常,Cassandra 未启动
- python - Python:使用 gmap.marker_layer 选项在地图上标记标签无法使用 hover_text