Net6 对接Apollo 分布式配置中心

 

部署Apollo

1 docker-compose快速构建

  • 在Github下载Docker-Compose部署文件

https://github.com/apolloconfig/apollo/tree/master/scripts/docker-quick-start

  • 通过Docker-Compose快速搭建Apollo环境

 

.NET6项目接入Apollo 

引入依赖

<PackageReference Include="Com.Ctrip.Framework.Apollo.Configuration" Version="2.5.0" />

 在Program.css类中添加

builder.WebHost.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) =>
{
    configurationBuilder.AddApollo(hostBuilderContext.Configuration.GetSection("apollo"))
    .AddNamespace("OrderService-Namespace", ConfigFileFormat.Json).AddDefault();
});

 

修改appsettings.json

{
  "apollo": {
    "AppId": "orderService-Config",
    "MetaServer": "http://192.168.3.254:8080",
    "ConfigServer": [ "http://192.168.3.254:8080" ],
    "Env": "DEV"
  }
}

 

 
posted @ 2022-02-23 21:10  非著名架构师  阅读(615)  评论(0编辑  收藏  举报