Under .NET CORE2.2 Ocelot + Consul stepped pit service discovery records

After historical reasons, the author of the company's project is still in use .NET CORE 2.2 version, complete the registration service in all business application upgrades found the last remaining Ocelot gateway service upgrades. During the upgrade process, we encountered some problems, document text, so that students have the same situation of reference.

1. Ocelot upgrade service discovery

According to official documents , by adding a simple configuration, either change the original configuration service discovery:

  1. Plug
    Install-Package Ocelot.Provider.Consul 13.5.2, the final version of the .Net Core 2.x

  2. Configuration Service

s.AddOcelot()
    .AddConsul();
  1. Adding a global profile
"ServiceDiscoveryProvider": {
    "Host": "localhost",
    "Port": 8500,
    "Type": "Consul"
}
  1. Configuring Routing
{
    "DownstreamPathTemplate": "/api/values}",
    "DownstreamScheme": "https",
    "UpstreamPathTemplate": "/spider/api/values",
    "UpstreamHttpMethod": [ "Get" ],
    "ServiceName": "spider",
    "LoadBalancerOptions": {
        "Type": "LeastConnection"
    },
}

2. problems

A few simple steps, Ocelot upgrade is complete, but after testing, but found not to Ocelot we expected, routed to the back-end services, but reported the following error:

At first thought it was a configuration problem, until the log level raised to Debug, a more detailed view of the log was found, URL request of the downstream splicing problems.

Specifically, it is using the Node Name Consul Ocelot service node, rather than the IP address of the corresponding node of the service.

Since the problem located, then read the source code should be able to find the cause, according to the first information packet nuget navigation https://github.com/ThreeMammals/Ocelot.Provider.Consul address Check Provider source code, after load testing, I found that actually is normal, but there is a doubt, this source repository, only the earliest of several versions of the tag, subsequent versions are not, through the search, have been incorporated into subsequent versions of the original Ocelot main library, and the project URL Nuget package is not updated, sweat!

Since the problem with the version of it read a bit Issue List, really found the problem, but also look at the issue under discussion, stepped into the pit should be a lot. Please refer to the following link directly to specific reasons:

https://github.com/ThreeMammals/Ocelot/issues/954

to sum up

  1. In the .NET CORE 2.x versions should be used 13.5.1 and earlier, Node Name or will cause problems.
  2. Ocelot.Provider.Consul source code has been merged into the main library Ocelot Portal

Guess you like

Origin www.cnblogs.com/xboo/p/12659842.html