I'm Ocelot student. How to setup Consul service discovery? #2285
-
Using version 23.4.3 does not support automatic discovery of Consul service. Can you add examples in samples? Nuget can automatically discover Consul services using 19.0.4 {
"Routes": [
{
"UpstreamPathTemplate": "/WeatherForecast", //访问下游服务的路径
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"DownstreamPathTemplate": "/WeatherForecast", //下游服务的控制器路径
"DownstreamScheme": "http",
"LoadBalancerOptions": { //负载均衡策略
"Type": "RoundRobin" //"LeastConnection"
},
"ServiceName": "ksjhaoka", //服务名称
"UseServiceDiscovery": true //使用服务发现
}
],
"GlobalConfiguration": {
"BaseUrl": "http://donesoft.cn.ocelotgateway:8080", //网关的地址
"ServiceDiscoveryProvider": {
"Type": "Consul",
"Host": "consul_server", //consul的服务名称
"Port": 8500
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello! What are your name and social links?
To be honest, you reported that something is broken. We will work together to find the cause.
We have detailed instructions on how to use Service Discovery with Consul. Please follow these instructions to set up basic configuration of Ocelot + Consul. Additionally, ensure that hosts in
Version 19.0.4 exists, but there is no official release this (version 19.0.4 was uploaded to NuGet a day before official 20.0 release). Perhaps you meant version 20.0? I can confirm that numerous updates have been introduced since version 20.0, and you will need a plan to migrate to version 23.4.3. I am here to you with this. Let's examine your configuration. While it may appear correct, I would like to highlight a few important points.
Therefore, I anticipate that the following configuration will be more pertinent for your learning scenario: {
"Routes": [
{ // regular route
"UpstreamPathTemplate": "/WeatherForecast",
// Do not define HTTP verbs then all verbs are applicable
//"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"DownstreamPathTemplate": "/WeatherForecast",
"DownstreamScheme": "http",
// Definition of a Load Balancer is not required for learning scenarios
//"LoadBalancerOptions": ...,
"DownstreamHostAndPorts": [
{ "Host": "localhost", "Port": 1234 } // specify your real downstream props
]
},
{
"UpstreamPathTemplate": "/WeatherForecast", //访问下游服务的路径
"UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ],
"DownstreamPathTemplate": "/WeatherForecast", //下游服务的控制器路径
"DownstreamScheme": "http",
"LoadBalancerOptions": { //负载均衡策略
"Type": "RoundRobin" //"LeastConnection"
},
"ServiceName": "ksjhaoka", //服务名称
"UseServiceDiscovery": true //使用服务发现
}
],
"GlobalConfiguration": {
"BaseUrl": "http://donesoft.cn.ocelotgateway:8080", //网关的地址
"ServiceDiscoveryProvider": {
"Type": "Consul",
"Host": "consul_server", //consul的服务名称
"Port": 8500
}
}
} Hope it helps! |
Beta Was this translation helpful? Give feedback.
Hello! What are your name and social links?
To be honest, you reported that something is broken. We will work together to find the cause.
We have detailed instructions on how to use Service Discovery with Consul. Please follow these instructions to set up basic configuration of Ocelot + Consul. Additionally, ensure that hosts in
ocelot.json
are online and able to serve your requests: check DNS names and network availability.Version 19.0.4 exists, but there is no official release this (version 19.0.4 was uploaded …