Bar*_*ski 2 service-discovery azure-service-fabric
我正在 Azure Service Fabric 中创建无状态服务。但是,一旦服务启动(或在自定义通信侦听器启动时),我需要获取该服务的所有其他实例/分区的地址。
我这样做是通过创建 newFabricClient
并调用fabricClient.QueryManager.GetPartitionListAsync(serviceUri)
. 但是我收到FabricServiceNotFoundException
消息服务不存在。当第一个服务实例开始运行时。
我在文档中找不到它,所以我的问题是:当该服务的新实例开始运行时,如何获取在 Azure Service Fabric 中运行的特定服务的所有活动实例的侦听端点地址列表?
端点地址实际上位于服务副本和实例上——这些是实际放置在节点上的东西。在ServiceManagerClient 中有一个特殊的方法,称为ResolveServicePartitionAsync。
在 Reliable Services SDK(在 Microsoft.ServiceFabric.Services.Client 命名空间中)中,我们提供了一个解析器实用程序,使这更容易一些:
ServicePartitionResolver resolver = ServicePartitionResolver.GetDefault();
ResolvedServicePartition partition =
await resolver.ResolveAsync(new Uri("fabric:/MyApp/MyService"), new ServicePartitionKey(), cancellationToken);
Run Code Online (Sandbox Code Playgroud)
ResolvedServicePartition 的 Endpoints 属性是分区中每个副本/实例的列表。Address 属性将包含一个 JSON 对象,它是一个键值对列表,其中包含由副本/实例打开的每个侦听器:
{
"Endpoints" :
{ "mylistener1" : "some-address" },
{ "mylistener2" : "some-address" }
...
}
Run Code Online (Sandbox Code Playgroud)
请记住,副本/实例出现的时间没有保证的顺序,因此您可能需要重试几次。此外,副本和实例会在服务的整个生命周期中不时移动,因此您需要使列表保持最新。基本上,您真的不能一次性获得所有这些信息并进行设置,因为它是一个非常动态的系统。
请参阅此处了解概述:https : //azure.microsoft.com/en-us/documentation/articles/service-fabric-connect-and-communicate-with-services/
在这里了解更多详细信息:https : //azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication/
归档时间: |
|
查看次数: |
1861 次 |
最近记录: |