Public void ConfigureServices (IServiceCollection services)
{
Services. AddMvc (.) SetCompatibilityVersion (CompatibilityVersion Version_2_1);
Services. AddOcelot (Configuration)
AddConsul ()
AddConfigStoredInConsul ()
AddPolly ();
}
Once the method using AddConfigStoredInConsul (), will start the project after page error 500, internal service error, if you do not use this method and reroute the downstream service, the plaintext configuration of IP and port, you can normal request
2. I added a name in the consul for TestApiServer services, and use the following configuration in the ocelot
{
"UseServiceDiscovery" : true,//use Consul service discovery
"DownstreamPathTemplate" : "/API/{url}",
"DownstreamScheme" : "HTTP",
"ServiceName" : "TestApiServer,"
"LoadBalancerOptions" : {
"Type" : "RoundRobin
"},
"UpstreamPathTemplate" : "/TestApiServer/{url},"
"UpstreamHttpMethod:"/" Get ", "Post",
"RateLimitOptions" : {
"ClientWhitelist" : "admin"],//white list
"EnableRateLimiting" : true,//whether to enable current-limiting
"Period" : "1 m",//statistical Period: 1 s, 5 m, 1 h, 1 d
"PeriodTimespan" : 15,//how many seconds after the client can retry
"Limit" : 10//statistical period to allow the maximum number of requests in
}
}
When I was a request for http://192.168.22.122:8000/TestApiServer/values, ocelot couldn't find the corresponding service to forward my request, are free, to come in for help
CodePudding user response:
The service can be adjustable