Azure Service Fabric – Criar serviço de descoberta de cache
Agora que os serviços de cluster e gerenciamento foram criados, NCache é criado um serviço de descoberta que serve ao propósito de adquirir os endereços IP do NCache servidores e fornecê-los aos aplicativos clientes. É um ASP sem estado.NET Core API web e consulta o serviço de nomenclatura do Azure Service Fabric para obter os pontos de extremidade registrados pelo NCache serviço de cluster e fornecê-los aos clientes como resposta HTTP.
Azure Service Fabric: arquivo de manifesto de serviço a ser criado NCache Serviço de descoberta
O arquivo de manifesto de serviço contém os terminais pelo ouvinte de comunicação para obter a porta para escutar.
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="NCacheDiscoveryPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="NCacheDiscoveryType" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>NCacheDiscovery.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
</EnvironmentVariables>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0.0" />
<Resources>
<Endpoints>
<Endpoint Protocol="http" Name="ServiceEndpoint" UriScheme="http" Port="55100" Type="Input" />
</Endpoints>
</Resources>
</ServiceManifest>
Aqui está um trecho de código do NCache Aplicativo Service Discovery em que o serviço chama o Serviço de Nomenclatura do Azure Service Fabric para obter acesso aos pontos finais registrados pelo NCache Serviço.
// Beginning Code
string serviceUri = $"fabric:/ServiceFabricApplication/NCacheService";
ServicePartitionResolver resolver = ServicePartitionResolver.GetDefault();
ResolvedServicePartition resolvedServicePartition = await resolver.ResolveAsync(new Uri(serviceUri), new ServicePartitionKey(), new System.Threading.CancellationToken());
var endpoints = resolvedServicePartition.Endpoints;
var endpointDictionary =
new Dictionary<string, List<string>>();
JObject addresses;
string bridge_management_address;
string cache_management_address;
string cache_client_address;
string bridge_client_address;
foreach (var endpoint1 in endpoints)
{
addresses = JObject.Parse(endpoint1.Address);
bridge_management_address = (string)addresses["Endpoints"]["bridge-management"];
cache_management_address = (string)addresses["Endpoints"]["cache-management"];
cache_client_address = (string)addresses["Endpoints"]["cache-client"];
bridge_client_address = (string)addresses["Endpoints"]["bridge-client"];
if (!endpointDictionary.ContainsKey("bridge-management"))
{
endpointDictionary["bridge-management"] = new List<string>();
}
if (!endpointDictionary.ContainsKey("cache-management"))
{
endpointDictionary["cache-management"] = new List<string>();
}
if (!endpointDictionary.ContainsKey("cache-client"))
{
endpointDictionary["cache-client"] = new List<string>();
}
if (!endpointDictionary.ContainsKey("bridge-client"))
{
endpointDictionary["bridge-client"] = new List<string>();
}
endpointDictionary["bridge-management"].Add(bridge_management_address);
endpointDictionary["cache-management"].Add(cache_management_address);
endpointDictionary["cache-client"].Add(cache_client_address);
endpointDictionary["bridge-client"].Add(bridge_client_address);
}
// Rest of code
Veja também
Implantando NCache no Azure Service Fabric
Criar cluster do Service Fabric
Crie NCache Serviço de cluster
Crie NCache Serviço de Gestão