Skip to main content
Version: Next

Etcd 方式注册 ShenYu 网关

ASP.NET Core 项目#

对于 ASP.NET Core 项目,我们可以参考这个 example code。你需要做以下步骤。

  1. 将 ShenYu 加入到 ASP.NET Core 项目依赖中。
dotnet add package <todo-shenyu-asp.net-core package>
  1. Startup.ConfigureServices 中加入 ShenyuRegister service。
public void ConfigureServices(IServiceCollection services){    ...    services.AddShenyuRegister(this.Configuration);    ...}
  1. appsettings.json 中进行配置。
{  "Shenyu": {    "Register": {      "ServerList": "http://127.0.0.1:2379",      "RegisterType": "etcd",      "Props": {        // etcd userName,if have not set ectd server userName,this parmas can empty        "UserName": "",        // etcd password,if have not set ectd server password,this parmas can empty        "Password": "",        // 3000 ms default        "EtcdTimeout": 4000,        // 5 ms default        "EtcdTTL": 15      }    },    "Client": {      "AppName": "dotnetexampleetcd",      "ContextPath": "/etcddotnet",      "IsFull": false,      "ClientType": "http"    }  }}
  1. 开启允许通过 ip 访问

当运行 ASP.NET Core 项目时,默认只能通过 localhost 访问。想要允许 ip 访问,需要设置下 ASPNETCORE_URLS 环境变量。

export ASPNETCORE_URLS=http://+:5000
  1. 启动 application
# build projectdotnet build --configuration Release# start projectcd examples/AspNetCoreExample/bin/Release/netcoreapp3.1dotnet AspNetCoreExample.dll

至此,你已经完成所有的步骤,可以进入 shenyu-admin 页面看到这些 API 已经注册到 ShenYu.

Last updated on by loongs-zhang