我有一个非常晦涩的问题,我现在已经努力解决了两三天,我有一个.Net核心应用程序,我部署在K8s。
这是我的部分代码片段。
public static async Task<MessageTranslationResDto> GetRedisCache(string uuid, string languageCode, string messageCode, string channel, IDistributedCache distributedCache, IConfiguration configuration)
{
try
{
var URL = configuration["MessageTranslationService"];
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(URL);
var StartTimeAPI = DateTime.Now;
var httpContent = new StringContent(System.Text.Json.JsonSerializer.Serialize(messageTransalationReqDto), Encoding.UTF8, "application/json");
var response = await client.PostAsync(URL, httpContent);
var responseContent = await response.Content.ReadAsStringAsync();
var user = JsonConvert.DeserializeObject<MessageTranslationResDto>(responseContent);
var redival = configuration["RedisExpiration"];
if (!String.IsNullOrEmpty(redival))
{
Console.WriteLine("RedisExpiration is : " + redival);
}
else
{
Console.WriteLine("RedisExpiration is not available");
}
}
catch (Exception ex)
{
}
}
和Yaml文件如下,
apiVersion: v1
kind: ConfigMap
metadata:
labels:
app: ms-common
name: ms-common-configmap
data:
appsettings.common.json: |-
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"RabbitMQ": {
"HostUrl": "*"
}
"ConnectionStrings": {
"DMAIN": "***",
"DADMIN": "***"
},
"Environment": "Dev",
"Otlp": {
"Endpoint": ""
},
"AspNetCoreInstrumentation": {
"RecordException": "true"
},
"UseTracingExporter": "otlp",
"UseMetricsExporter": "otlp",
"ExceptionHandlingService": "",
"RedisConnection": "***",
"MessageTranslationService": "http://test/api/message",
"RedisExpiration": "30"
}
---
apiVersion: v1
kind: Secret
metadata:
labels:
app: ms-common
name: ms-common-secret
data:
MessageTranslationService: dsdsdssd==
ExceptionHandlingService: dsdsdsdsdsfs==
RedisConnection: cm########wMA==
ConnectionStrings__DMAIN: test1=
ConnectionStrings__DADMIN: test==
type: Opaque
问题是在获取**"RedisExpiration"
时,它始终返回null
。在获取配置值时,仅为此"RedisExpiration"
值返回null
,其他值 正确接收。例如"MessageTranslationService"
**。可能的原因是什么?
1条答案
按热度按时间ssgvzors1#
您可以尝试使用base64手动解码您的值吗?