我似乎无法弄清楚如何使用 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);
}
}
关于c# - Service Fabric - 为有状态服务调用命名分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45123773/