.net core Ocelot路由配置中的路径冲突

.net core Ocelot路由配置中的路径冲突,.net-core,microservices,url-routing,service-discovery,ocelot,.net Core,Microservices,Url Routing,Service Discovery,Ocelot,您将如何设置沿两组相似路线重新运行到不同的机器。请告知 问题/问题:冲突的情况是/customers/1和/customers/1/产品之间的冲突,其中每一个产品都将连接到不同的机器 -机器名称:客户 -机器名称:customerproduct ocelot.json 只是在评论中根据OP自己的解决方案添加一个答案 这不起作用的原因是评估的顺序。Ocelot将按照指定的顺序计算路径,除非在路由上指定了优先级属性(参见文档) 因此,在以下路由配置中: { "ReRoutes":[

您将如何设置沿两组相似路线重新运行到不同的机器。请告知

问题/问题:冲突的情况是
/customers/1
/customers/1/产品之间的冲突,其中每一个产品都将连接到不同的机器

-机器名称:
客户
-机器名称:
customerproduct
ocelot.json
只是在评论中根据OP自己的解决方案添加一个答案

这不起作用的原因是评估的顺序。Ocelot将按照指定的顺序计算路径,除非在路由上指定了优先级属性(参见文档)

因此,在以下路由配置中:

{
   "ReRoutes":[
      {
         "UpstreamPathTemplate":"/customers/{id}", // <-- will be evaluated first
         ...
      },
      {
         "UpstreamPathTemplate":"/customers/{id}/products",
         ...
      },
      ...
   ],
   ...
}
{
“重新路由”:[
{

“UpstreamPathTemplate”:“/customers/{id}”,//为什么不起作用?出现了什么错误?问题是
/customers/{id}
/customers/1
/customers/1/product1
都被截获,通过更改顺序解决,将最具体的路线向上移动到通用路线。您想将此作为答案添加还是我应该这样做:)我已经这样做了。希望如此感谢优先级示例。
GET /customers/1/products
PUT /customers/1/products
 {
  "ReRoutes": [

    {  
      "DownstreamPathTemplate": "/customers/{id}", 
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "customer",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/customers/{id}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
    },

    {
      "DownstreamPathTemplate": "/customers/{id}/products",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "customerproduct",
          "Port": 80
        }
      ],
      "UpstreamPathTemplate": "/customers/{id}/products",
      "UpstreamHttpMethod": [ "Get", "Put" ]
    }

  ],

  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:80"
  }

}
{
   "ReRoutes":[
      {
         "UpstreamPathTemplate":"/customers/{id}", // <-- will be evaluated first
         ...
      },
      {
         "UpstreamPathTemplate":"/customers/{id}/products",
         ...
      },
      ...
   ],
   ...
}
{
   "ReRoutes":[
      {
         "UpstreamPathTemplate":"/customers/{id}/products", // <-- will be evaluated first
         ...
      },
      {
         "UpstreamPathTemplate":"/customers/{id}",
         ...
      },
      ...
   ],
   ...
}
{
   "ReRoutes":[
      {
         "UpstreamPathTemplate":"/customers/{id}",
         "Priority": 0, 
         ...
      },
      {
         "UpstreamPathTemplate":"/customers/{id}/products", // <-- will be evaluated first
         "Priority": 1, 
         ...
      },
      ...
   ],
   ...
}