Unable to connect with Steeltoe 3.0 connector to Redis

195 views Asked by At

I have recently upgraded Steeltoe versions from 2.4.3 to 3.0.1. After making the required changes, it looks like my application is not able to connect to Redis hosted in VMWare Cloud Foundry. The heath check actuator is down with below error

RedisConnectionException: It was not possible to connect to the redis server(s). UnableToConnect on localhost:6379/Interactive, Initializing/NotStarted, last: NONE, origin: BeginConnectAsync, outstanding: 0, last-read: 0s ago, last-write: 0s ago, keep-alive: 60s, state: Connecting, mgr: 10 of 10 available, last-heartbeat: never, global: 60283s ago, v: 2.1.58.34321.

My Program.cs looks like below

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>();
            });
}

My .csproj looks like below.

<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" />

My Startup.cs looks like below.

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();
        });
    }
}

Looks like connector is not able to get the credentials from VCAP_SERVICES and finally defaulting to localhost. Any pointers why so? Thanks in advance

1

There are 1 answers

2
Tim On

In order to pick up bindings from VCAP_SERVICES in Steeltoe 3.0 you'll need to also add this to your .csproj:

<PackageReference Include="Steeltoe.Connector.CloudFoundry" Version="3.0.1" />

https://docs.steeltoe.io/api/v3/connectors/usage.html#cloud-foundry