zoukankan      html  css  js  c++  java
  • .net core使用nacos作为配置中心

    拉取镜像并创建容器

    docker pull nacos/nacos-server
    docker run --env MODE=standalone --name nacos -d -p 8848:8848 nacos/nacos-server

    创建配置

    image-20210611201316776

    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;
    
    }
    
  • 相关阅读:
    maven常用命令介绍(持续更新)
    JQ笔记
    AspNetPager学习使用2
    AspNetPager学习使用1
    VS2012添加ADO实体数据模型
    手动拍摄0008
    程序自动拍摄0007
    曝光补偿0006
    白平衡0005
    感光度0004
  • 原文地址:https://www.cnblogs.com/xinzhyu/p/14876419.html
Copyright © 2011-2022 走看看