Alexandar Rajavel
Alexandar Rajavel

Reputation: 21

Steeltoe Refresh not working as expected(not reloading the config values without restarting application) in .NET core 3.1

Problems is not getting(updated) the latest config values without restarting the application.

//My Code is: 

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using Steeltoe.Management.Endpoint;
using Steeltoe.Management.Endpoint.Refresh;


//Startup class:
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();

    services.AddOptions();

    services.AddRefreshActuator();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseRouting();

    app.UseAuthorization();
    app.UseCustomSwagger();

    app.UseEndpoints(endpoints =>
    {
        endpoints.Map<RefreshEndpoint>();
        endpoints.MapControllers();
    });

}


//Controller class:

namespace DemoAppForRefresh.Controllers
{
    [ApiController]
    [Produces("application/json")]
    public class ReRouteController : ControllerBase
    {

        private readonly IConfigurationRoot _configuration;


        public ReRouteController(IConfigurationRoot configuration)
        {

            _configuration = configuration;

        }

        [HttpGet("v1/test")]
        public IActionResult GetTestValue()
        {

            return Ok(new { ConfigurationUrl = _configuration.GetValue<string>("vendor-route:url") });
        }
    }
}

If I change any configuration values while the application is running, it has no effect.

In other words that you can't get the most recent configuration values unless you restart the application.

I referred this link:click here

So please help on this.

Upvotes: 0

Views: 249

Answers (1)

Tim
Tim

Reputation: 2707

It looks like you've added the Refresh actuator correctly, but the actuator does not automatically refresh when your configuration changes. The refresh should now be triggerable via HTTP request - Have you issued a GET request to /actuator/refresh?

Upvotes: 0

Related Questions