Running our spring boot application takes 2-3 minutes to boot. Bulk of the time was spent on connecting to different servers via Spring Cloud Consul Discovery Client.
I'm looking for a way to cache service discovery in a separate application like in the following diagram:
+----------------------+ +----------------------+
| | | |
| Target Server | | Consul Server |
| | | |
+-----------^----------+ +-----------^----------+
|(3) |(2)
| |
+----------------------+ +----------------------+
| |(1) | |
| Application |---> | Consul Client Cache |
| | | |
+----------------------+ +----------------------+
- Application queries consul client cache instead consul server directly to retrieve the network address of the target server.
- Consul Client Cache is a standalone application where it loads and caches the IP addresses of the services registered in consul server.
- Application connects to target server.
At the top of my mind, I believe this is possible by:
- Writing a spring boot application of consul client cache wherein it caches the services registered in consul server and serves them to the application upon request.
- Intercept the HTTP requests of application and re-route to consul client cache server.
But this seems a generic problem so I'm hoping there is already a ready-made solution out there.
Anyone has ideas?
Spring actuator from here provides a refresh endpoint that can dynamically reload application properties in runtime.
You can define a "ManagedResource" that has a scope refresh bean.
You don't need to intercept anything, just make the application talk only to the Consul server. Then the consul server can decide whether a certain property should be fetched from the cache or not. I Used Netflix's Eureka in the past to manage the application properties of multiple spring boot apps, but it seems HashiCorp's Consul server is a fully functional replacement of Eureka.