我有一个 Service Fabric Actor 服务。这将创建两个项目,ActorService
和ActorService.Interfaces
.
ActorService.Interfaces 包含根 actor 的接口(interface),名为 IRootActor
。 ActorService本身包含RootActor
和IChildActor
, 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/