.net core使用nacos作為配置中心
阿新 • • 發佈:2021-06-11
拉取映象並建立容器
docker pull nacos/nacos-server
docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server
建立配置
core裡寫程式碼讀取配置
安裝包 nacos-sdk-csharp-unofficial
//ConfigureServices services.AddNacos(configure => { // default timeout configure.DefaultTimeOut = 8; // nacos's endpoint configure.ServerAddresses = new System.Collections.Generic.List<string> { "http://192.168.114.131:8848" }; // namespace configure.Namespace = ""; // listen interval configure.ListenInterval = 1000; }); //使用的地方可以注入 // private readonly INacosConfigClient _configClient; [HttpGet] public async Task<string> Get() { var res = await _configClient.GetConfigAsync(new GetConfigRequest { DataId = "redis", Group = "DEFAULT_GROUP", Tenant = "Public" }); return string.IsNullOrWhiteSpace(res) ? "Not Found:" + await _configClient.GetServerStatus() : res; }