Fetching multiple configs from Spring Cloud Config Server in one request - spring

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

Related

Spring cloud config server for multiple stage

I'm working with spring cloud config server, and my need is to create a configuration file for each stage prod test and dev, I already created 4 yml file application.yml for the default profile, application-{profiles} for each profile, so my question is how to load the specific configuration through the environment variable and run the config server on each profile configuration and port , I already created a bootstrap.yml but I can't solve the issue.
I will be very thankful if someone can guide throught the steps to achieve my need.
You don't need to start Spring Cloud Config Server with different profiles and on different port per environment. You can have one Config Server that manages the configurations for all environments. In your client's bootstrap.yml you will need to provide the URL of your Config Server as follows:
spring:
cloud:
config:
uri: http://your-config-server
When you run your client application with a particular profile (e.g. via an environment variable spring_profiles_active=dev), Spring Cloud Config Client will fetch the configuration properties from Config Server for the targeted profile.
I recommend to review at least the Quick Start section of the Spring Cloud Config documentation and try the examples provides there.

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!

spring-cloud-config client without starting a server

I have short lived task with client to spring cloud config.
(dependency to spring-cloud-starter-config or spring-cloud-config-client).
As I mention, this is short lived task that start, load configurations from the server, do some processing, and closed.
the problem is that spring-cloud-config-client start web server (tomcat), and this is redundant- I don't want to start a web server on my client application/task.
I understand that this web server give me the abilities to refresh or update my short lived task, but I doesn't need it.
Is there a way to use spring-cloud-config client without starting a server on the client application?
I got the same issue and found a solution, so here it is:
For spring boot 2 you can use a configuration (yaml format)
spring:
main:
web-application-type: none
For spring boot 1.x it is
spring:
main:
web-environment: false

Modify spring cloud config server in the client

I have a spring boot powered spring cloud application with a configuration server running seperately on port say 8001 on localhost.
Meanwhile, location has been specified in the config client applications/micro services as below in the bootstrap.yml file of the client project.
spring:
cloud:
config:
uri: http://localhost:8001
This works absolutely fine.
However when i want to deploy the whole application on different setups, i would need to run the config server on different IPs and Ports.
In that case i can not go and change the IP:Port information of the config server in all the projects, rebuild the jar and deploy them. In fact in most scenarios, Jenkins build the Jars by itself on different environment.
How can we handle such situation? Can we specify an environment variable in the bootstrap.yml, if yes how to do it?
Any suggestion?
Br,
AJ
You can definitely use environment variables in your bootstrap.yml file:
spring:
cloud:
config:
uri: http://${configServerHost}:${configServerPort}
When you launch your application you only have to add -DconfigServerHost=localhost -DconfigServerPort=8001

Spring cloud config client without Eureka, Ribbon and spring boot

I have spring web application (not spring boot) running in AWS. I am trying to create centralized configuration server. How to refresh the spring-cloud-client after the changing the properties? As per tutorial
Actuator endpoint by sending an empty HTTP POST to the client’s refresh endpoint, http://localhost:8080/refresh, and then confirm it worked by reviewing the http://localhost:8080/message endpoint.
But my aws Ec2 instances are behind the loadbalancer so i can't invoke the client url. I didn't understand the netflix Eureka and Ribbon much but it seems like adding another level of load balancer in the client side. I don't like this approach. Just to change a property i don't want to make the existing project unnecessarily complex. Is there any other way? or Am I misunderstood Eureka/Ribbon usage?
I have looked at the spring-cloud-config-client-without-spring-boot, spring-cloud-config-client-without-auto-configuration none of them have answer. First thread was answered in 2015. Wondering is there any update?
To get the configuration properties from a config server. You can do a http request. Example:
From the documentation we can see:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml <- example
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
So if you would do a request to http://localhost:8080/applicationName-activeProfile.yml you would receive the properties in .yml format for the application with that name and active profile. Spring boot config clients would automatically provide these values but you will have to provide em manually.
You don't need Eureka/Ribbon for this to work, it's a separate component.
More info: http://cloud.spring.io/spring-cloud-static/spring-cloud.html#_spring_cloud_config
Maybe you could even use spring-cloud-config but I'm not sure what extra configuration is needed without spring-boot.
https://cloud.spring.io/spring-cloud-config/

Resources