Spring cloud config server for multiple stage - microservices

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.

Related

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

spring cloud data flow custom app config to pass enviromental variables

i am working on Spring cloud data flow Custom source application which gets data from an rest endpoint . I use Spring cloud data flow and Skipper server to push this custom jar to PCF (Pivotal Cloud Foundry) .This works fine but now i want to pass some custom environmental properties to the application .Below is the yaml config i used to deploy the jar to the repo . tried passing below it under the env bucket but seems its not getting picked by the application at runtime..Please suggest
DB_HOST:host_url
DB_PORT:3306
DB_SCHEMA:test
DB_USER: user
DB_PASS:pwd
application.yml for pusing the CUSTOM SOURCE to SCDF App Repo
---
applications:
- name: pocclient
memory: 2G
instances: 1
path: ../target/custom-sink-client-0.0.17-SNAPSHOT.jar
buildpacks:
- java_buildpack
env:
JAVA_VERSION: 1.8.0_+
SPRING_PROFILES_ACTIVE: cloud
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
DB_HOST:host_url
DB_PORT:port
DB_SCHEMA:test
DB_USER:
DB_PASS:
Based on the limited details in the description, it is unclear what you're trying to do with SCDF and a custom-sink, and likewise, in which platform are you provisioning all the components. You may want to edit the post with more details.
In Cloud Foundry, if you want SCDF to deploy apps with config-server binding automatically, you would want to review the ref. guide for more information. The service-instance must exist in the same Org/Space, and the service-instance name is expected to be configured in SCDF, so when SCDF deploys apps on your behalf, it will also bind the app with the service-instance automatically.
In Kubernetes, it'd be a similar mechanism; however, you're expected to provide the config-server URI configuration as an environment variable when deploying the desired apps as bare-pods.

spring cloud config client set config url at property file

I have a spring cloud project. There are config server (config-srv), eureka server (eureka-srv) and some other service with business logic, let's call it main service (main-srv).
I'm packaging them into jars and run one by one. My apps get their properties from a file in the same directory with jars.
So, I'm setting properties to config-srv through "application-native.properties".
But if i want to change config-srv url (for example, i want http://localhost:9999), how can i share this url for all micro-services before they will boot ? I'm trying to share this url in "application-default.properties" but it makes no effect.
You can put the Spring Cloud Config server details in bootstrap.properties file in each microservices.
spring.application.name=microserviceName
spring.profiles.active=dev
spring.cloud.config.uri=http://localhost:9999
spring.cloud.config.username=your_username
spring.cloud.config.password=your_password
Go through the link to have more detail about spring cloud config
https://howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/

In Spring Cloud, does micro-services read their configurations from Eureka or it only reads from config server?

I am following this video to learn micro-services.
My questions is: Can micro-services read configuration from config service through Eureka, or they can only read configurations directly from config server ?
I am trying to configure and make a client read its configuration from eureka but with no success.
You can use the following option in your bootstrap.yml
spring.cloud.config.discovery.enabled=true
And you also need to specify the the service id of your config service.
spring.cloud.config.discovery.serviceId=xxxx
serviceId is usually the the application name.
If you do like above, your microservivces will try to find the address of config server via discovery service.
You can find more details here.

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

Resources