获得对ActorService的访问权限,以获取所有演员的列表

时间:2019-06-20 13:38:30

标签: azure-service-fabric

尝试学习Azure Service Fabric的基础知识。我有一个应用程序正在工作,我在其中创建了UserActorService,我可以创建和检索actor以及在其中保存状态。但是我不知道如何获得所有演员的名单。

我对这段代码有一些了解:

     public async Task<List<string>> GetAllUserActors()
    {
        var fabricClient = new FabricClient();
        var cancellationTokenSource = new CancellationTokenSource();
        ContinuationToken continuationToken = null;
        var result = new List<string>();

        do
        {
            var page = await actorService.GetActorsAsync(continuationToken, cancellationTokenSource.Token);
            result.AddRange(page.Items.Select(i => i.ActorId.ToString()).ToList());
            continuationToken = page.ContinuationToken;

        } while (continuationToken != null);

        return result;
    }

问题是我不知道该放在哪里。该代码需要访问实际的userActor服务ActorService。而且在UserActorService中,我只能在UserActor中保留它。我想我可以将UserActor放入其中,然后调用单个UserActor来获取此方法,并返回一个列表。

但是我不应该这样,因为我认为我不需要知道一个UserActor的ID就能看到那里有哪些actor。

1 个答案:

答案 0 :(得分:0)

您可以在集群中的任何应用程序中使用SF Remoting来获取数据:

IActorService actorServiceProxy = ActorServiceProxy.Create(
    new Uri("fabric:/MyApp/MyService"), partitionKey);    
ContinuationToken continuationToken = null;
List<ActorInformation> activeActors = new List<ActorInformation>();

do
{
    PagedResult<ActorInformation> page = await actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken);    
    activeActors.AddRange(page.Items.Where(x => x.IsActive));    
    continuationToken = page.ContinuationToken;
}
while (continuationToken != null);

通过传递各自的partitionKey,确保对每个Actor服务分区重复该呼叫。

更多信息here