Search code examples
azure-service-fabric

Find partition key of stateful service at runtime


I need to find the current partition key of a Service Fabric Stateful Service at run time.

I have looked in the ICodePackageActivationContext and the StatefulServiceContext but can't seem to see this information anywhere.

Edit:

As LoekD pointed out in his answer this information is available from within the StatefulService class. Just to be explicitly clear, here is how I accessed:

var info = (Int64RangePartitionInformation) this.Partition.PartitionInfo;

var highKey = info.HighKey;
var lowKey = info.LowKey;

Solution

  • From within the service itself, you can use the Partition.PartitionInfo property.