4

我正在遵循Service Fabric spawn actor on startup中的建议,以便在服务启动时生成几个 actor。我有一个具有以下 RunAsync 覆盖的自定义 ActorService 子类:

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

4

1 回答 1

3

从您的自定义参与者服务中删除以下代码:

     protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners() 
 { 
   var remotingListener = new ServiceReplicaListener(context => this.CreateServiceRemotingListener(context)); 
   return new ServiceReplicaListener[] { remotingListener }; 
 } 

这将删除基础 ActorService 正在设置的 ActorRemotingListener。如果您想添加额外的侦听器,请调用基本 CreateServiceReplicaListeners 方法,获取侦听器,然后添加自定义侦听器。

于 2016-06-24T18:08:10.017 回答