spring-cloud-aws icon indicating copy to clipboard operation
spring-cloud-aws copied to clipboard

Parameter Store: Support for periodic polling / refresh

Open jmkgreen opened this issue 6 years ago • 4 comments

I have recently added Parameter Store support via this library in addition to the existing Consul support to our application of ours. The latter periodically polls Consul for values and applies them to the application context - this makes it incredibly useful when we need to adjust logging levels, for instance.

We do not see such behaviour with the Parameter Store support in this library. Would it be possible to port across the functionality? The same may be relevant to Secrets Manager support, although there may be ramifications for connections such as JDBC.

jmkgreen avatar Mar 04 '19 21:03 jmkgreen

I currently have tested this

@RefreshScope
@RestController
public class HelloRestController {

	@Value("${hello.message}")
	private String hello;

	@GetMapping("/hello/{name}")
	public String hello(@PathVariable String name) {
		return this.hello + " " + name;
	}
}
  1. Create aws ssm put-parameter --name "/config/application/hello.message" --type String --value "Hello"
  2. Start application
  3. See Hello
  4. Update aws ssm put-parameter --name "/config/application/hello.message" --value "Hola" --overwrite
  5. Perform curl -X POST http://localhost:8080/actuator/refresh
  6. See "Hola"

Make sure you have spring-boot-starter-actuator dependency and the following property management.endpoints.web.exposure.include=refresh.

eddumelendez avatar Oct 26 '20 03:10 eddumelendez

I currently have tested this

@RefreshScope
@RestController
public class HelloRestController {

	@Value("${hello.message}")
	private String hello;

	@GetMapping("/hello/{name}")
	public String hello(@PathVariable String name) {
		return this.hello + " " + name;
	}
}
  1. Create aws ssm put-parameter --name "/config/application/hello.message" --type String --value "Hello"
  2. Start application
  3. See Hello
  4. Update aws ssm put-parameter --name "/config/application/hello.message" --value "Hola" --overwrite
  5. Perform curl -X POST http://localhost:8080/actuator/refresh
  6. See "Hola"

Make sure you have spring-boot-starter-actuator dependency and the following property management.endpoints.web.exposure.include=refresh.

Any recommended approach when running multiple replicas of the service behind a load balancer?

Thanks and best regards.

ips219 avatar Jul 19 '21 11:07 ips219

hi I have the same question, what we should do when we run hundreds of replicas of our microservice?

aka-toxa avatar Dec 17 '21 13:12 aka-toxa

If eventual consistency is appropriate for the system, then properties pooling can be implemented through a scheduled context refresh.

@AllArgsConstructor
@Configuration
@EnableScheduling
public class ContextRefreshConfig {

   private final ContextRefresher contextRefresher;

   @Scheduled(initialDelay = {value}, fixedRate = {value})
   void refreshProperties() {
       contextRefresher.refresh();
   }
   
}

yyatsiuk avatar Dec 17 '21 16:12 yyatsiuk