Last active
July 1, 2016 01:50
-
-
Save CESARDELATORRE/f74204845a0b47ec6fe7ed95dfb1dc4a to your computer and use it in GitHub Desktop.
This code tells you the Partition's Range Keys (High and Low) of your current partition in a Service Fabric Stateful Reliable Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code can run in any Azure Service Fabric Stateful Reliable Service | |
// within the method protected override async Task RunAsync(CancellationToken cancellationToken) | |
//Aditional or similar code in: https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/Services/WordCount/WordCount.WebService/Controllers/DefaultController.cs | |
var fabricClient = new FabricClient(); | |
string serviceUri = "fabric:/MySFApp/MyStatefulService"; | |
Uri serviceUriInstance = new Uri(serviceUri); | |
System.Fabric.Query.ServicePartitionList partitionList = | |
await fabricClient.QueryManager.GetPartitionListAsync(serviceUriInstance); | |
foreach (var partition in partitionList) | |
{ | |
if(partition.PartitionInformation.Id == this.Context.PartitionId) | |
{ | |
if (partition.PartitionInformation.Kind == ServicePartitionKind.Int64Range) | |
{ | |
Int64RangePartitionInformation currentInt64RangePartition = (Int64RangePartitionInformation)partition.PartitionInformation; | |
ServiceEventSource.Current.ServiceMessage(this, "Partition ID: {0} -- HighKey: {1} -- LowKey: {2}", | |
this.Context.PartitionId, | |
currentInt64RangePartition.HighKey, | |
currentInt64RangePartition.LowKey); | |
} | |
else | |
{ | |
ServiceEventSource.Current.ServiceMessage(this, "Partition is not Int64Range"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment