when spring cloud config server calls the github repository? - spring

I mean spring cloud config server fetches all client api's configuration during startup ?
or
spring cloud config server fetch the client API configuration, when that client api calls the config server?

That behaviour is controllable via a property:
spring.cloud.config.server.git.clone-on-start
Flag to indicate that the repository should be cloned on startup (not on demand). Generally leads to slower startup but faster first query.
Default:
false
So the default behaviour is that the repo will only be cloned when a client first makes a request to the server, but if you set the property to true, then the server will clone the repository when it starts and the configuration will be available to the client's first request faster

Related

How to configure database connection runtime in Spring Boot?

I made a new Spring Boot project using the Spring Initializr. I'm building an On-premise backend so what I'm trying to achieve is that when the user opens the jar executable and the server starts, he should be able to configure the database connection by going to localhost:8080/ in his web browser. Basically the index.html will have a form with 4 fields for IP Address, Database Name, UserName and Password. When the form is submitted spring will try to connect to the database with the provided information.
I have all my entities, repositories and controllers but currently the only way i can connect to a database is with the application.properties file, but since the user wont have access to the source, there should be a way for him to configure his database.
Thanks for your time!
I would suggest to use the Spring cloud Config server to store database related properties which is capable of picking up configuration at run time. Although it is typically configured with a Git repository, you can store them locally as pointed out in this thread.

Spring Cloud Config Server on Pivotal Cloud Foundry

I have two microservices. A Spring Cloud Config Server and another module that implements Spring Cloud Config Client. When I use the default configuration for the Spring Cloud Config Server service (localhost:8888) I can start it locally without any issues, after which I can start my other module as well, using a bootstrap.yml, it clearly finds the Config Server, fetches its properties and starts properly. All good. Now I'd like to push both of these services to Pivotal Cloud Foundry.
The Config Server service works just fine, service is up and running in my Space, and using the browser I can verify that it can still fetch the property files from the specific GitHub repository.
The problem is the other module, the client. I've replaced the default localhost:8888 in its bootstrap.yml file (spring.cloud.config.url parameter) to the now active service in the cloud using the Route bound to it and tried to start it locally. Unfortunately now it simply timeouts during startup. At this point I tried to specify longer timeouts but nothing helps.
Interesting thing is that if I directly copy the URL from the logs that timeouts I see it works properly in the browser locally. So why not in IntelliJ when I try to package the client with the changed parameter?
Sorry, I can't include much details here, but I hope maybe there is a straightforward solution that I've missed. Thanks!

Fetching multiple configs from Spring Cloud Config Server in one request

One of our apps uses Spring Cloud Config Server to store client configs. I.e. not the configs needed to start the, but the configs sent later to client. Basically, JSONs. It's a controversial solution, but it is as it is. It uses Spring Cloud Config Server client to fetch them directly from the server.
The problem is that it fetches them one by one and that the number of configs is huge (100th of parameters). As a result, this fetching process takes too long.
Is there a way to fetch multiple configs at once in one request in Spring Cloud Config Server?
Yes you can do that. Its designed for config sharing between apps.
In your bootstrap.yml, add all the configurations you want to fetch from server in the spring.cloud.config.name property as following:
spring:
cloud:
config:
uri: xxxxxxx
.....
name: myconfiguration1, myconfiguration2,...etc
keep in mind that all depends on the activated profile. So if your spring.profiles.active is dev i.e, the configurations that will be fetched all myconfiguration1-dev.yml, myconfiguration2-dev.yml...etc

Using Spring cloud config in multi application architecture

I am currently using Spring external configuration by creating a config server, config client and a Git repository with property files. Is there any way to use this config server for multiple applications?
My Current Architecture:
Created a Git repository with config files.
Created a Config Server which connects to the above Git repository for property files.
Created a Client (Spring boot application) which connects to the config server to load the properties.
When there is a change in any of the property files, I am invoking the refresh method of config client to refresh the properties. If there are multiple applications using the same config server and git repository for property files, what should be the approach to refresh all the properties without invoking the /refresh method of all the applications?
I tried /refresh of the config server but it doesn't refresh the properties as they are loaded during the application startup.

Spring Cloud Config Server

I am using the Spring Cloud Config Server and able to detect the changes from the git repository and pass it to the Config clients.
There are two ways, I have implemented it:
After making changes (commit and push) in the git repository, I make a curl request curl -X POST http://server:port/bus/refresh and it works fine. For this I am using RabbitMQ as the Spring Cloud Bus.
Reference:
http://tech.asimio.net/2017/02/02/Refreshable-Configuration-using-Spring-Cloud-Config-Server-Spring-Cloud-Bus-RabbitMQ-and-Git.html
After making changes (commit and push) in the git repository, I make a curl request curl -X POST http://server:port/refresh (with no /bus in the url) and it works fine. I am NOT using Spring Cloud Bus here.
Reference: https://spring.io/guides/gs/centralized-configuration/
So both works fine, so Is there any advantage of using Spring Cloud Bus, or in Production environment, will there be any issue with going without Spring Cloud Bus? As there will be extra effort needed to get setup the RabbitMQ Cluster (HA) as Spring Cloud Bus in production.
Thanks,
David
/refresh will only refresh the config client to whom the request was made. It only refreshes locally. Using /bus/refresh will refresh all clients connected to the bus. In other words it will refresh all bus clients (or a subset if the destination parameter is set).

Resources