目前參考兩篇文章,已實作基本的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啟動,可以看到同時啟動三個專案
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/105821.html
標籤:.NET Core
