/// <summary> /// This is the main entry point for your service instance. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service instance.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { string applicationName = FabricRuntime.GetActivationContext().ApplicationName; while (true) { await Task.Delay(this.healthCheckFrequency, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); HttpClient httpClient = this.CreateHttpClient(); await Task.WhenAll( // TODO: Add additional health checks for your application this.CheckServiceHealthAsync(new Uri($"{applicationName}/Frontend"), async(serviceName, partition) => { string requestUri = new NamedService(serviceName).BuildEndpointUri(endpointName: "web") + $"default.html"; var response = await httpClient.GetAsync(requestUri); return(response.IsSuccessStatusCode ? null : $"Request {response.RequestMessage.RequestUri} failed with {response.StatusCode}"); }, cancellationToken), this.CheckServiceHealthAsync(new Uri($"{applicationName}/ValuesService"), async(serviceName, partition) => { string requestUri = new NamedService(serviceName).BuildEndpointUri(endpointName: "web", target: HttpServiceUriTarget.Primary, partitionKey: 0) + "api/values/"; var response = await httpClient.GetAsync(requestUri); return(response.IsSuccessStatusCode ? null : $"Request {response.RequestMessage.RequestUri} failed with {response.StatusCode}"); }, cancellationToken)); this.Partition.ReportPartitionHealth(this.RunSelfCheck()); } }
public static string BuildEndpointUri(this NamedService service, string endpointName, HttpServiceUriTarget target, long partitionKey, EndpointScheme scheme = EndpointScheme.HTTP) { return(BuildEndpointUri(service, endpointName, target, new ServicePartitionKey(partitionKey), scheme.ToString())); }
public void TestMethod2() { NamedService service = new NamedService(new NamedApplication("fabric:/testapp"), "myservice"); string s1 = service.BuildEndpointUri("endpoint", EndpointScheme.HTTPS); Assert.AreEqual(s1, "https://fabric/testapp/myservice/#//Any/endpoint/"); string s2 = service.BuildEndpointUri("endpoint", HttpServiceUriTarget.Primary, partitionKey: 123, scheme: EndpointScheme.HTTPS); Assert.AreEqual(s2, "https://fabric/testapp/myservice/#/123/Primary/endpoint/"); }
private static string BuildEndpointUri(NamedService service, string endpointName, HttpServiceUriTarget target, ServicePartitionKey partitionKey, string scheme) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (string.IsNullOrEmpty(scheme)) { throw new ArgumentException(nameof(scheme)); } HttpServiceUriBuilder builder = new HttpServiceUriBuilder(); builder.SetScheme(scheme); builder.SetServiceName(service); builder.SetPartitionKey(partitionKey); builder.SetEndpointName(endpointName); builder.SetTarget(target); return(builder.Build().OriginalString); }
public static string BuildEndpointUri(this NamedService service, string endpointName, EndpointScheme scheme = EndpointScheme.HTTP) { return(BuildEndpointUri(service, endpointName, HttpServiceUriTarget.Any, null, scheme.ToString())); }