我最近将 Steeltoe 版本从 2.4.3 升级到 3.0.1。进行所需更改后,我的应用程序似乎无法连接到托管在 VMWare Cloud Foundry 中的 Redis。健康检查执行器停机并出现以下错误
RedisConnectionException:无法连接到 redis 服务器。UnableToConnect on localhost:6379/Interactive,Initializing/NotStarted,last:NONE,origin:BeginConnectAsync,未完成:0,last-read:0s 前,last-write:0s 前,keep-alive:60s,状态:Connecting,mgr: 10 个可用的 10 个,最后一次心跳:从不,全球:60283 秒前,v:2.1.58.34321。
我的 Program.cs 如下所示
public static class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.AddCloudFoundryConfiguration()
.ConfigureLogging((builderContext, loggingBuilder) =>
{
// Add Serilog Dynamic Logger
loggingBuilder.ClearProviders();
loggingBuilder.AddDynamicSerilog();
})
.AddCloudFoundryActuators()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
我的 .csproj 如下所示。
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Steeltoe.Common.Hosting" Version="3.0.1" />
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicSerilogCore" Version="3.0.1" />
<PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="3.0.1" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="3.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="StackExchange.Redis" Version="2.1.58" />
<PackageReference Include="Steeltoe.Connector.ConnectorCore" Version="3.0.1" />
我的 Startup.cs 如下所示。
public class Startup
{
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = configuration;
HostingEnvironment = env;
}
public IConfiguration Configuration { get; }
public IWebHostEnvironment HostingEnvironment { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRouting(options => options.LowercaseUrls = true);
// Add StackExchange IConnectionMultiplexer configured from Cloud Foundry
services.AddRedisConnectionMultiplexer(configuration);
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
看起来连接器无法从 VCAP_SERVICES 获取凭据,最终默认为 localhost。任何指针为什么会这样?提前致谢