ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.24k stars 1.62k forks source link

help me ocelot+consul has 404 #2117

Closed liujian1368928 closed 1 week ago

liujian1368928 commented 1 week ago

I use windows11, and the ocelot agent is successfully installed on a local PC. I want to add the ocelot+consul discovery service and agent. I always failed 404 when accessing the proxy interface, I found a lot of information, change all https to http, change host, etc., who can help me, ocelot console error message below.This is machine translation. There may be errors

Error

warn: Ocelot.Provider.Consul.DefaultConsulServiceBuilder[0]
      requestId: 0HN4UFH6RITO4:00000005, previousRequestId: No PreviousRequestId, message: 'Unable to use service address: 'http://localhost' and port: 5165 as it is invalid for the service: 'OrderService'. Address must contain host only eg. 'localhost', and port must be greater than 0.'
warn: Ocelot.Provider.Consul.DefaultConsulServiceBuilder[0]
      requestId: 0HN4UFH6RITO4:00000005, previousRequestId: No PreviousRequestId, message: 'Unable to use service address: 'http://localhost' and port: 5165 as it is invalid for the service: 'OrderService'. Address must contain host only e.g. 'localhost', and port must be greater than 0.'
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HN4UFH6RITO4:00000005, previousRequestId: No PreviousRequestId, message: 'Error Code: ServicesAreEmptyError Message: There were no services in RoundRobin during Lease operation. errors found in ResponderMiddleware. Settin error response for request path:/order, request method: GET'
warn: Ocelot.DownstreamRouteFinder.Middleware.DownstreamRouteFinderMiddleware[0]
      requestId: 0HN4UFH6RITO4:00000006, previousRequestId: No PreviousRequestId, message: 'DownstreamRouteFinderMiddleware setting pipeline errors. IDownstreamRouteFinder returned Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /order/test, verb: GET.'
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HN4UFH6RITO4:00000006, previousRequestId: No PreviousRequestId, message: 'Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /order/test, verb: GET. errors found in ResponderMiddleware. Setting error response for request path:/order/test, request method: GET'

Actual Behavior / Motivation for New Feature

image

my ocelot.json

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/Order", ///{matchall}",
      "DownstreamScheme": "https",
      "UpstreamPathTemplate": "/Order",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "ServiceName": "OrderService",
      "UseServiceDiscovery": true,
      "LoadBalancerOptions": {
        "Type": "RoundRobin" // "RoundRobin"
      }
      //"DownstreamHostAndPorts": [
      //  {
      //    "Host": "localhost",
      //    "Port": 7166
      //  }
      //]

    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5100",
    "ServiceDiscoveryProvider": {
      "Scheme": "http",
      "Host": "localhost",
      "Port": 8500,
      "Type": "Consul",
      "PollingInterval": 1000
    }
  }
}

Steps to Reproduce the Problem

1. 1. 1.

Specifications

raman-m commented 1 week ago

Hello, @liujian1368928 ! The error is self- explanatory. Address host "http://localhost" is invalid! Host must be IP address or DNS name. Please edit your service in Consul, and remove scheme http from service address.

Hope it helps!

P.S. Your service DNS name is localhost.

liujian1368928 commented 1 week ago

你好, !错误是不言自明的。地址主机“http://localhost”无效!主机必须是 IP 地址或 DNS 名称。请在 Consul 中编辑您的服务,并从服务地址中删除方案。http

希望对您有所帮助!

P.S. 您的服务 DNS 名称是 。localhost

Hello, after translation, I don't quite understand your meaning, is my api resource host changed to ip access, then 127.0.0.1? I used it to register to consul, but still had problems. Or other meaning?

raman-m commented 1 week ago

As far as I know, you can use host DNS name or just IP address as a Consul service address. Please read Consul documentation.

Regarding your problems... We are not consulting firm, but you've reported officially this issue. Seems you had to create a discussion. Seems you learn Consul and Ocelot. If you still believe there is a problem in Ocelot, and if you need a recommendation then provide more details please.