【发布时间】:2019-08-28 16:42:24
【问题描述】:
我刚刚开始为我的 Service Fabric 应用程序编写一些动态端点发现,并且正在寻找有关如何解析服务端点的示例。我在stackoverflow上找到了以下代码示例:
https://stackoverflow.com/a/38562986/4787510
我对此做了一些小的改动,所以这是我的代码:
private readonly FabricClient m_fabricClient
public async Task RefreshEndpointList()
{
var appList = await m_fabricClient.QueryManager.GetApplicationListAsync();
var app = appList.Single(x => x.ApplicationName.ToString().Contains("<MyFabricDeploymentName>"));
// Go through all running services
foreach (var service in await m_fabricClient.QueryManager.GetServiceListAsync(app.ApplicationName))
{
var partitions = await m_fabricClient.QueryManager.GetPartitionListAsync(service.ServiceName);
// Go through all partitions
foreach (var partition in partitions)
{
// Check what kind of service we have - depending on that the resolver figures out the endpoints.
// E.g. Singleton is easy as it is just one endpoint, otherwise we need some load balancing later on
ServicePartitionKey key;
switch (partition.PartitionInformation.Kind)
{
case ServicePartitionKind.Singleton:
key = ServicePartitionKey.Singleton;
break;
case ServicePartitionKind.Int64Range:
var longKey = (Int64RangePartitionInformation)partition.PartitionInformation;
key = new ServicePartitionKey(longKey.LowKey);
break;
case ServicePartitionKind.Named:
var namedKey = (NamedPartitionInformation)partition.PartitionInformation;
key = new ServicePartitionKey(namedKey.Name);
break;
default:
throw new ArgumentOutOfRangeException($"Can't resolve partition kind for partition with id {partition.PartitionInformation.Id}");
}
var resolvedServicePartition = await ServicePartitionResolver.GetDefault().ResolveAsync(service.ServiceName, key, CancellationToken.None);
m_endpointCache.PutItem(service.ServiceTypeName, new ServiceDetail(service.ServiceTypeName, service.ServiceKind, ServicePartitionKind.Int64Range, resolvedServicePartition.Endpoints));
}
}
}
}
我很高兴找到了这个 sn-p,但是在处理它的过程中,我发现了一件让我有点困惑的事情。
所以,在阅读了 SF 文档之后,据我了解,这似乎是它从上到下遵循的架构:
Service Fabric 集群 -> Service Fabric 应用程序(例如 myApp_Fabric)-> 服务(例如,前端服务、个人资料图片微服务、后端服务)
从服务中我们可以深入了解分区,而分区基本上类似于集群中节点上的“容器”,可以驻留多个实例(副本),实例是服务的实际部署。
不过,我不太确定节点/分区/副本的差异是否正确。
但是,回到我的困惑和实际问题:
为什么分区策略的信息(singleton、intRange、named)附加到分区信息,而不是服务本身?据我了解,分区基本上是我将服务配置为跨服务结构节点分布的产物。
那么,为什么分区策略不直接与服务绑定?
【问题讨论】:
标签: azure azure-service-fabric