01 .NET CORE 2.2 使用OCELOT -- 简单使用

 

  目前参考两篇文章,已实现基本的ocelot的网关功能。

  https://www.cnblogs.com/xlxr45/p/11320988.html

  https://www.jianshu.com/p/c967eda8b04d

 

  按照第一篇的操作,ocelot的网关宿主为cmd,因为本想用webapi项目引用ocelot实现网关功能,配置文件有点出入。

  后来搜索查到第二篇。简单修改下配置,configuration.json 如下

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/customers",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 9001
        }
      ],
      "UpstreamPathTemplate": "/customers",
      "UpstreamHttpMethod": [ "Get" ]
    },
    {
      "DownstreamPathTemplate": "/api/customers/{id}",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 9001
        }
      ],
      "UpstreamPathTemplate": "/customers/{id}",
      "UpstreamHttpMethod": [ "Get" ]
    },
    {
      "DownstreamPathTemplate": "/api/products",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 9002
        }
      ],
      "UpstreamPathTemplate": "/api/products",
      "UpstreamHttpMethod": [ "Get" ]
    }
  ]
}

 

  修改三个项目的启动宿主为iisexpress、端口等,并在解决方案中设置为多项目启动。

  VS按F5启动,可以看到同时启动三个项目

posted @ 2019-10-17 16:19  枫欣慧20151010  阅读(421)  评论(0编辑  收藏  举报