Skip to content

Commit 2f2eb2f

Browse files
authored
Merge pull request #89202 from WhitWaldo/patch-12
Update service-fabric-reliable-actors-enumerate.md
2 parents 52830d1 + fa37090 commit 2f2eb2f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

articles/service-fabric/service-fabric-reliable-actors-enumerate.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,41 @@ do
5353
while (continuationToken != null);
5454
```
5555

56+
While the code above will retrieve all the actors in a given partition, occasionally the need will arise to query the IDs of all actors (active or inactive) across each partition. This should be done by exception as it's quite a heavy task.
57+
58+
The following example demonstrates how to query the partitions of the service and iterate through each in combination with the above example to produce a list of all the active and inactive actors in the service across the Service Fabric application:
59+
60+
61+
```csharp
62+
63+
var serviceName = new Uri("fabric:/MyApp/MyService");
64+
65+
//As the FabricClient is expensive to create, it should be shared as much as possible
66+
FabricClient fabricClient = new();
67+
68+
//List each of the service's partitions
69+
ServicePartitionList partitions = await fabricClient.QueryManager.GetPartitionListAsync(serviceName);
70+
71+
List<Guid> actorIds = new();
72+
73+
foreach(var partition in partitions)
74+
{
75+
//Retrieve the partition information
76+
Int64RangePartitionInformation partitionInformation = (Int64RangePartitionInformation)partition.PartitionInformation; //Actors are restricted to the uniform Int64 scheme per https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-actors-introduction#distribution-and-failover
77+
IActorService actorServiceProxy = ActorServiceProxy.Create(serviceName, partitionInformation.LowKey);
78+
79+
ContinuationToken? continuationToken = null;
80+
81+
do
82+
{
83+
var page = await actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken);
84+
actorIds.AddRange(page.Items.Select(actor => actor.ActorId.GetGuidId());
85+
continuationToken = page.ContinuationToken;
86+
} while (continuationToken != null);
87+
}
88+
89+
return actorIds;
90+
```
5691

5792

5893
## Next steps

0 commit comments

Comments
 (0)