Modify spring cloud config server in the client - spring-boot

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

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.

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

App deployed on PCF trying to find config at localhost:8888 even when the cloud foundry provided config server is binded with app

How do we make use of Spring Cloud Services like Config Services/ Hystrix at PCF? I have one app deployed on PCF and i am trying to bind a Config server service from CF marketplace to it. But when i start the app it tries to connect localhost:8888. Any Idea what can be done?
manifest.yml
---
applications:
- name: demo
memory: 4096M
host: demo
domain: apps.pcf.devfg.***.com
services:
- ps-config-server-pcf
Ensure that you have these two Libraries in your build.gradle and the bind your App to the Marketplace service
io.pivotal.spring.cloud:spring-cloud-services-starter-config-client
org.springframework.cloud:spring-cloud-config-server
Also, remove all your local configurations from your bootstrap.yml (however PCF will over ride your values, this is a good practice to do)

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.

Deploy Spring War locally

How can I deploy my Spring Boot microservice on my ubuntu server, so that only the localhost can access it.
For example I got a user-service : localhost:8888.
I dont want to this to be accessible globaly. Only the localhost should be able to do that.
Thanks for your help
If you set server.address to localhost then your app is not accessible from outside.
Set the following in the application.properties
server.address=127.0.0.1

Resources