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

标签 c# azure-service-fabric

我似乎无法弄清楚如何使用 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/

相关文章:

c# - 默认服务描述不能作为升级的一部分进行修改 将 EnableDefaultServicesUpgrade 设置为 true

Azure Service Fabric 本地部署导致 DnsService 错误 : DnsService UDP listener is unable to start

c# - 无法使用 WebClient.DownloadFile 方法从启用了 TLS 1.1/1.2 协议(protocol)的计算机下载文件

c# - 如何在sql数据库后端插入2个值的总和

Azure Service Fabric - 服务互通和耦合

c# - IReliableDictionary 上的 Linq 查询

azure-service-fabric - 如何枚举所有分区和聚合结果

c# - CallContext LogicalGet(Set)Data 在带有异步/等待的 NUnit 框架上不起作用?

c# - 如何获取所有正在运行的 ASP.NET 工作进程及其关联的应用程序池的列表?

c# - 在现有项目上创建 View 模型