我遵循Service Fabric spawn actor on startup中的建议在服务启动时生成几个参与者。我有一个自定义ActorService子类,具有以下RunAsync重写:
internal sealed class InternalCustomActorService : ActorService
{
protected async override Task RunAsync(CancellationToken cancellationToken)
{
await base.RunAsync(cancellationToken);
for(int i = 0; i < 10; i++)
{
ICustomActor proxy = ActorProxy.Create<ICustomActor>(new ActorId(i));
await proxy.StartAsync();
}
}
...
该类在program.cs中注册如下:
ActorRuntime.RegisterActorAsync<CustomActor>(
(context, actorType) => new InternalCustomActorService(context, actorType, () => new CustomActor())).GetAwaiter().GetResult();
但是,调用
proxy.StartAsync()
方法时出现以下异常:FatalExecutionEngineError occurred
HResult=-2146233088
Message=One or more errors occurred.
Source=Microsoft.ServiceFabric.Services
StackTrace:
at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.<InvokeWithRetryAsync>d__7`1.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Remoting.Client.ServiceRemotingPartitionClient.<InvokeAsync>d__8.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<InvokeAsync>d__0.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<ContinueWith>d__b.MoveNext()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at CustomActorService.InternalCustomActorService.<RunAsync>d__2.MoveNext() in C:\_data\Master\CONSTABLE2\Apps\BSP\Research\ServiceFabric\CustomActorServiceApp\CustomActorService\InternalCustomActorService.cs:line 47
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<ExecuteRunAsync>d__e.MoveNext()
InnerException:
HResult=-2147467263
Message=Interface id '1830616258' is not implemented by object 'CustomActorService.InternalCustomActorService'
Source=Microsoft.ServiceFabric.Services
InnerException:
示例项目位于github上https://github.com/PaloMraz/CustomActorServiceApp
我的问题是:我做错了什么?
编辑:我试图添加额外的
BootstrapperService
无状态服务,并在BootstrapperService.RunAsync
中从那里生成参与者:protected override async Task RunAsync(CancellationToken cancellationToken)
{
await base.RunAsync(cancellationToken);
await Task.Delay(10000);
for (int i = 0; i < 10; i++)
{
ICustomActor proxy = ActorProxy.Create<ICustomActor>(new ActorId(i));
await proxy.StartAsync();
}
}
尽管如此,调用
proxy.StartAsync()
抛出的异常与上面的InternalCustomActorService.RunAsync
中的异常完全相同。 最佳答案
从自定义参与者服务中删除以下代码:
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
var remotingListener = new ServiceReplicaListener(context => this.CreateServiceRemotingListener(context));
return new ServiceReplicaListener[] { remotingListener };
}
这将删除基本ActorService正在设置的ActorRemotingListener。如果要添加其他侦听器,请调用基本createservicereplicalisteners方法,获取侦听器,然后添加自定义侦听器。