I tested two scenarios by hashicorp consul
1.I implemented service discovery by hashicorp consul on .net7 , but when i want get service address from consul , it just return http of that service not https.
I registered my services by registrator on docker and discover servicces by .net dockerized too.
2.but i test this scenario on my localhost
i implemented two apis on localhost and registered one of them on consul that was running on docker server
I've seen that when i discover api1 from api2 through consul , I requested https of api1 but consul switch and change it to http and it works and i get result of that.
but the same situation on my server(scenario1) doesnt work
my implementation:
services.AddServiceDiscovery(options => options.UseConsul());
//HttpClinetFactory
services.AddHttpClient("DiscoveryRandom").ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain,sslPolicyErrors) => true,
}).AddHttpMessageHandler().AddServiceDiscovery();
// I inject : IHttpClientFactory clientFactory
_httpClient = clientFactory.CreateClient("DiscoveryRandom");
_httpClient.BaseAddress = new Uri($"https://{ServiceName on consul}");
// my appsetting for scenario 1 that register done by docker on server and i just doscovered it through consul:
"$schema": "https://steeltoe.io/schema/latest/schema.json",
"Consul": {
"Host": "10.200.8.178",
"Discovery": {
"Register": false
}
}
// my appsetting for scenario 2 that register done by myself on localhost:
// setting for api1 to register on consul
"$schema": "https://steeltoe.io/schema/latest/schema.json",
"Consul": {
"Host": "10.200.8.178",
"Discovery": {
"Register": true,
"serviceName": "TestConsul",
"hostName": "localhost",
"port": 7141,
"deregister": false
}
}
// and setting for service discovery api2
"$schema": "https://steeltoe.io/schema/latest/schema.json",
"Consul": {
"Host": "10.200.8.178",
"Discovery": {
"Register": false
}
}