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

2022-10-14,,,,

 

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

  

  

 

  按照第一篇的操作,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启动,可以看到同时启动三个项目

《01 .NET CORE 2.2 使用OCELOT -- 简单使用.doc》

下载本文的Word格式文档,以方便收藏与打印。