apolloconfig / apollo.net

Apollo .Net Client
Apache License 2.0
483 stars 168 forks source link

.net core无法读取到配置 #46

Closed caopengfei closed 5 years ago

caopengfei commented 5 years ago

Configuration.GetValue("ApNames")返回数据是null,我确认已经在web上设置值了的 自动生成了C:\opt\data\baidu\config-cache文件夹,但是文件夹里面是空的。 客户端有debug功能吗?可以打印日志信息吗?现在有问题都无从查起。

caopengfei commented 5 years ago

TIM截图20190412172147 TIM截图20190412172147 直接打开接口地址(http://192.168.1.253:8080/configs/baidu/dev/application)是有数据的,见上图

caopengfei commented 5 years ago

TIM截图20190412172147 这个是appsetting.json

philiahe commented 5 years ago

启动的脚本发一下。

caopengfei commented 5 years ago

启动的脚本发一下。

什么启动脚本?是启动apollo的脚本吗?我是用的docker方式启动的(https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker部署

philiahe commented 5 years ago

启动dotnetcore的脚本

caopengfei commented 5 years ago

F5调试模式

caopengfei commented 5 years ago

TIM截图20190412172147 这个是配置apollo的代码

philiahe commented 5 years ago

直接引源码,调试,还可以把有个logprovider改成console看下日志。

pengweiqhca commented 5 years ago

加这个调试试试

Com.Ctrip.Framework.Apollo.Logging.LogManager.Provider = new ConsoleLoggerProvider(LogLevel.Trace);
caopengfei commented 5 years ago

加上了,但是控制台还是没有任何与apollo相关的信息打印出来。

pengweiqhca commented 5 years ago

那看看builder.Build().GetSection("apollo").GetChildren().ToArray()是否有值

caopengfei commented 5 years ago

控制台有输出了: 14:38:00 [Debug] refresh config services 14:38:00 [Debug] refresh config for namespace: application 14:38:00 [Debug] Loading config from http://172.20.0.3:8080/configs/baidu/dev/application?ip=192.168.1.250 14:38:05 [Warn] Could not complete get operation - Could not complete get operation [Cause: The operation has timed out.] 14:38:06 [Warn] refresh config error for namespace: application 14:38:06 [Debug] Long polling from http://172.20.0.3:8080/notifications/v2?appId=baidu&cluster=dev&notifications=%5B%7B%22namespaceName%22%3A%22application%22%2C%22notificationId%22%3A-1%7D%5D&ip=192.168.1.250 14:38:06 [Warn] Sync config from upstream repository Com.Ctrip.Framework.Apollo.Internals.RemoteConfigRepository failed, reason: Load Apollo Config failed - appId: baidu, cluster: dev, namespace: application, url: http://172.20.0.3:8080/configs/baidu/dev/application?ip=192.168.1.250 [Cause: Could not complete get operation [Cause: The operation has timed out.]] 14:38:06 [Warn] Loading config from local cache file C:\opt\data\baidu\config-cache\baidu+dev+application.json failed - Loading config from local cache file C:\opt\data\baidu\config-cache\baidu+dev+application.json failed [Cause: Could not find file 'C:\opt\data\baidu\config-cache\baidu+dev+application.json'.] info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\Users\admin\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. Hosting environment: Development Content root path: D:\Develop\Projects\net\BaiduAd\Rakor.Baidu.Ads.Web Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:5000/api/values info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0] Executing endpoint 'Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web)' info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1] Route matched with {action = "Get", controller = "Values"}. Executing action Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web) info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1] Executing action method Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web) - Validation state: Valid info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2] Executed action method Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web), returned result Microsoft.AspNetCore.Mvc.ObjectResult in 0.5901ms. info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1] Executing ObjectResult, writing value of type 'System.String[]'. info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2] Executed action Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web) in 55.03ms info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1] Executed endpoint 'Rakor.Baidu.Ads.Web.Controllers.ValuesController.Get (Rakor.Baidu.Ads.Web)' info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 409.1386ms 200 application/json; charset=utf-8 14:38:27 [Warn] Long polling failed, will retry in 1 seconds. appId: baidu, cluster: dev, namespace: application, long polling url: http://172.20.0.3:8080/notifications/v2?appId=baidu&cluster=dev&notifications=%5B%7B%22namespaceName%22%3A%22application%22%2C%22notificationId%22%3A-1%7D%5D&ip=192.168.1.250, reason: Could not complete get operation [Cause: One or more errors occurred. (由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。) [Cause: 由于连接方在 一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 [Cause: 由于连接方在一段时间后没有正确答复或连接的主机没有反 应,连接尝试失败。]]] 14:38:28 [Debug] Long polling from http://172.20.0.3:8080/notifications/v2?appId=baidu&cluster=dev&notifications=%5B%7B%22namespaceName%22%3A%22application%22%2C%22notificationId%22%3A-1%7D%5D&ip=192.168.1.250

pengweiqhca commented 5 years ago

http://172.20.0.3:8080网络不通?

caopengfei commented 5 years ago

我配置的MetaServer地址是http://192.168.1.253:8080,不知道这个http://172.20.0.3:8080是哪里来的

caopengfei commented 5 years ago

172.20.0.3是apollo的docker容器地址,外面是访问不到的

pengweiqhca commented 5 years ago

@nobodyiam 请给 @caopengfei 提供一个docker部署apollo的文档

caopengfei commented 5 years ago

@nobodyiam 请给 @caopengfei 提供一个docker部署apollo的文档

我是按你们wiki里面提供的docker部署说明操作的,这个不行吗?

caopengfei commented 5 years ago

@nobodyiam 请给 @caopengfei 提供一个docker部署apollo的文档

我是按你们wiki里面提供的docker部署说明操作的,这个不行吗?

那请提供我一个正确的吧

nobodyiam commented 5 years ago

@caopengfei 参考一下网络策略

Rstar-Yan commented 5 years ago

@nobodyiam 请给 @caopengfei 提供一个docker部署apollo的文档

我是按你们wiki里面提供的docker部署说明操作的,这个不行吗?

那请提供我一个正确的吧

最后怎么解决的?

pengweiqhca commented 5 years ago

@caopengfei @DekeYan 可以使用最新的包,已经添加跳过meta service发现的过程,直接配置configserver

gebiWangshushu commented 4 years ago

@pengweiqhca 我今天用最新的包,还是有同样的问题。包:Com.Ctrip.Framework.Apollo.Configuration Version=2.3.0

szg commented 4 years ago

@pengweiqhca 我今天用最新的包,还是有同样的问题。包:Com.Ctrip.Framework.Apollo.Configuration Version=2.3.0

在 apollo 配置 中增加 ConfigServer 节点 "ConfigServer": [ "http://127.0.0.1:8080/" ]

image