Service Fabric - 为有状态服务调用命名分区

Service Fabric - Calling a named partition for a stateful service

我似乎无法弄清楚如何使用 ServiceProxy 向特定的命名分区发送调用,而且似乎没有任何专门针对此的文档。这就是 Int64RangePartitionInformation

的做法
var partitionInformation = (Int64RangePartitionInformation)selectedPartition.PartitionInformation;
var partitionKey = ServicePartitionKey(partitionInformation.LowKey);    
IListen listenerClient = ServiceProxy.Create<IListen>(uri,partitionKey );

但似乎没有办法为 NamedPartitionInformation 获取 ServicePartitionKey。您是否在 Uri 或其他内容中包含分区名称?

ServicePartitionKey 有一个接受字符串的重载。

var partitionKey = new ServicePartitionKey("partitionName");
IListen listenerClient = ServiceProxy.Create<IListen>(uri,partitionKey);

您不需要做更多的事情。

但是,如果您不知道前面的分区并且需要查询它们:

using(var client = new FabricClient())
{
    var partitions = await client.QueryManager.GetPartitionListAsync(serviceName);

    foreach (var partition in partitions)
    {
        var partitionInformation = (NamedPartitionInformation)partition.PartitionInformation;
        var partitionKey = ServicePartitionKey(partitionInformation.Name);    
        IListen listenerClient = ServiceProxy.Create<IListen>(uri,partitionKey);
    }
}