Kyle Anderson
Kyle Anderson

Reputation: 7041

Update Spring Bean Property Across Multiple Servers

Here is my scenario: I have a Spring Bean called APIBean which acts as an API client to a remote REST service. This Bean contains a property called hostName which is the IP Address of the Remote Server. This functions as the base URI when the APIBean client makes REST calls. The initial value of this hostName property is pulled from application.properties.

The challenge I have is that the hostName property is subject to change. I have a web form where a User will update the hostName property when its address changes. This is pretty straightforward in a single instance environment, but my application is distributed in AWS and behind an Elastic Load Balancer.

So how should I go about applying this change to all other instances of this Spring Boot application?

I've looked at Spring Cloud Config which externalizes application.properties to a centralized Git repository. It even includes a /refresh endpoint which you can hit with a POST request to update Beans annotated with RefreshScope. But this endpoint only refreshes the single instance you are accessing. It does not affect any other distributed instance.

These frameworks are great and I feel the solution is close but I need a little help with the last mile. This must be a common development issue with distributed applications. How can we update a Spring Bean property across multiple servers?

Upvotes: 1

Views: 761

Answers (1)

Shawn Sherwood
Shawn Sherwood

Reputation: 1998

I think you are looking for Spring Cloud Bus: https://github.com/spring-cloud/spring-cloud-bus.

Upvotes: 1

Related Questions