c# - 无法在 Service Fabric 的一个 ActorRuntime 中注册两个 Actor

标签 c# azure-service-fabric

我有一个 Service Fabric Actor 服务。这将创建两个项目,ActorServiceActorService.Interfaces .

ActorService.Interfaces 包含根 actor 的接口(interface),名为 IRootActor 。 ActorService本身包含RootActorIChildActor , ChildActor 。这两个接口(interface)都实现 IActor ,这两个类都继承 Actor并实现各自的接口(interface)。我从 Program.cs 中注册这些参与者,如下所示:

ActorRuntime.RegisterActorAsync<ChildActor>(
   (context, actorType) => new ActorService(context, actorType, () => container.Resolve<ChildActor>()))
   .GetAwaiter()
   .GetResult();

ActorRuntime.RegisterActorAsync<RootActor>(
   (context, actorType) => new ActorService(context, actorType, () => container.Resolve<RootActor.Factory>()(context)))
   .GetAwaiter()
   .GetResult();

Thread.Sleep(Timeout.Infinite);

调用container.Resolve<RootActor.Factory>()(context)返回RootActor实例。

当我打电话时

IRootActory proxy = ActorProxy.Create<IRootActor>(new ActorId(id), actorServiceUri);
proxy.Method(data);

一切都很顺利。上述RootActor.Method方法在一个循环中执行两件事,创建子 Actor 并调用它的方法:

IChildActor proxy = ActorProxy.Create<IChildActor>(new ActorId(otherId), sameActorServiceUri);
proxy.OtherMethod(transformedData);

问题来了。经proxy.OtherMethod调用,本质上会出现这个疯狂的异常:

HResult=-2146232969 Message=No MethodDispatcher is found for interface id '230348154' Source=Microsoft.ServiceFabric.Actors

我在这里做错了什么吗?考虑到this SO thread ,我认为可以从一项服务创建两个参与者......

最佳答案

好吧,我明白了。对于任何陷入困境的人来说,问题出在参与者服务 URI 上。 我错误地假设两个参与者共享服务 URI。正如 the link I mentioned in the question 中提到的, Actor 们实际上是分开主持的。如果查看 ServiceManifest.xml 内部,您会发现两个 Extension xml 节点,它们都命名为 __GenerateServiceType__。所需要做的就是根据子 DefaultService xml 节点更改服务名称部分,因此在本例中它很可能是 ChildActorService。天哪,这听起来很不合适。

总而言之,Service Fabric 中任何内容的设置和配置都相当复杂。但是,VS 会尽力帮助您。有时你甚至没有想到,这实际上就是罪恶的根源。如果你不知道要寻找什么,你就不会去寻找它。

关于c# - 无法在 Service Fabric 的一个 ActorRuntime 中注册两个 Actor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40177671/

相关文章:

c# - 在 ASP.NET Core 中尽快获取当前 URL program.cs/startup.cs

c# - OData 连接服务与 OData V4 客户端代码生成器

c# - 具有多个输入参数的 Linq 表达式

c# - 如何在启用视觉样式的情况下将控件呈现为看起来像 ComboBox?

c# - 跨不同系统使用 Azure Service Fabric Reliable Actors

c# - Azure Service Fabric 持续集成在 Visual Studio Team Services 中失败(以前是 VSO)

c# - 如何在 TextBox Windows Phone 8.1 中更改文本的垂直对齐方式

azure - 即使使用 sudo,Yeoman 也会给出权限错误

Azure Service Fabric - 无法删除任何默认 NAT 规则

asp.net-mvc - 本地集群上托管的 Service Fabric 托管 Asp.net WebApi 容器应用程序 : 403 - Forbidden : Access is denied.