I'm new to the spring cloud config server. Consider a scenario where we have 10 spring boot microservice fetching configurations from the Spring Boot Cloud Config. I was wondering How the 10 spring boot microservices will work when the Spring Boot Cloud Config itself is down?
Can someone answer to below queries:
If the config server is down, Will there be downtime for all the microservice connected to it?
Let's say we have a config file application.properties in GitHub and Spring boot config refers to the application.properties file in GitHub What if the username and password to access the application.properties file itself will change?
In terms of Disaster recovery, Do we need any backup of the config server? If yes, How can we achieve the same?
If the config server is down, Will there be downtime for all the microservice connected to it?
In real world application, there will be multiple instances of your config server deployed across multiple availability zones, fronted by load balancer or API gateway, or even you can register your multiple instance with eureka server so that there is No single point of failure.
So how the configuration will look like is instance 1 is in us-east-1
instance 2 in us-west-2, so even if one AZ is down it will not impact your services.
As far as GitHub or external repo is concerned, you can configure config server to read properties natively but that not something I will suggest !!
Let's say we have a config file application.properties in GitHub and Spring boot config refers to the application.properties file in GitHub What if the username and password to access the application.properties file itself will change?
First of all you should not commit password in Github for public repo, secondly password should be dynamically fetched from Idvault, or AWS secret Manager or other services whichever you prefer. So that even if you change password it will not affect any services.
In terms of Disaster recovery, Do we need any backup of the config server? If yes, How can we achieve the same?
Config server is just reading properties/config from repo that you provide,so repository where your code is hosted is of importance to you. Github can take care of that for you !!
Related
I have to change my custom defined spring properties (defined via #ConfigurationProperties beans) during runtime of my Spring Boot application.
Is there any elegant way of doing this using Spring Cloud Config?
I don't want to use an external application.properties in a git repository (as the spring boot application gets shipped to customers and I dont' want to create a git repository for everyone of them).
I just want to access and change the local application.properties (the one in the classpath, located in src/main/resources) file in my Spring container or (if thats not possible) in the Spring Cloud Config Server, which I could embed into my Spring Boot app. Is that possible somehow?
BTW: The goal is to create a visual editor for the customers, so that they can change the application.properties during runtime in their spring boot app.
Spring Boot supports profile based application configuration. Just add application-<profile>.properties file. Then just when running the application select a profile depending on the environment making use of spring.profiles.active.
-Dspring.profiles.active=dev
This will run the application with application-dev.properties file (overriding the default application.properties, i.e you can just leave the common stuff in the default file and change the rest depending on the env)
On a side note, having a repo for configuration is not a must. You could just place them in the class path and give a search-location.
spring:
application:
name: config-server
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:configs/
It actually is possible and in the end quite easy to achieve. It just took me a whole day to get all the information together. Maybe this helps someone:
You basically just need Spring Actuator, but for a certain endpoint, you also need the spring cloud dependency. (to make Post requests to the /env endpoint of Spring Actuator)
To alter your config at runtime, just add the following to your application.properties:
management.endpoints.web.exposure.include: env,refresh
management.endpoint.env.post.enabled: true //this property is only available when spring cloud is added as dependency to your project
If you (like me) don't need the feature of an externalized config, then you also have to add the following (otherwise, your Spring app will not start and throw an error that some config is missing)
spring.cloud.config.enabled: false
Now, if you send a POST request to /actuator/env endpoint with an object in the HTTP body in the form of {"name":"...", "value":"..."} (name is the name of a config property), then your config gets changed. To check that, you can do a GET request to /actuator/env/[name_of_config_property] and see that your config property has changed. No need to restart your app.
Don't forget to secure the /actuator endpoint in your SecurityConfig if you use a custom one.
It seems to me that you neither need the #RefreshScope annotation at your config classes nor the /actuator/refresh endpoint to "apply" the config changes.
Maybe what your looking for could be achieved with Spring cloud config and spring cloud bus. It's explained here: https://cloud.spring.io/spring-cloud-config/reference/html/#_push_notifications_and_spring_cloud_bus
In summary, any change on configuration sent an event to the spring cloud bus and you can then reload app context or configuration with new properties.
I have a Spring Cloud Config server for configuration, a Eureka server for service discovery, and two app servers (App A and App B).
I'm trying to share a logging configuration (log4j2) between App A and App B by utilizing Spring Cloud Config for serving the configuration file. I can make the config file available from the server (http://localhost:1234/log4j2/default/config/log4j2.properties).
If I hardcode that value in my application configs (also served by my config server) then my applications can read the log4j config and everything works. However, I don't want to put the absolute URL of the config server in my application configuration file, as the config server information should be provided by the Eureka discovery server.
Sort of a chicken/egg problem. Does anybody have a method for resolving this?
How Do I connect to multiple bootstrap servers(DEV, STAGE and PROD) from a microservice ( Admin MS) with security in place?
I want to connect to all the kafka servers and create/manage topics, create ACLS etc.
I am using spring kafka adminclient , and configuring properties from application.yml using spring boot to connect to Dev right now. But now I want to connect to all environments.
Is there an easier and better approach other that wring a properties hashmap and putting config values in it. Does Spring cloud stream help?
Is this something similar to connecting multiple databases to a micro service ?
You can do it by creating multiple child boot applications, each with its own environment containing the properties.
But it's probably easier to bypass Boot's auto configuration and wire up your own AdminClients with their own properties.
I'm trying to migrate from monolithic web application to microservices.
For doing this I'm using JHipster v 4.11.1 (very helpful!).
My problem is:
In JHipster registry (central-config folder) I wrote some property files and every microservice, on startup, read the owned properties.
I need to change this properties on runtime both from registry and from every microservices.
There are any ways to do this? I have to use kafka or somethings like that?
JHipster Registry is a Spring Cloud Config server and should allow this behavior but I'm new with this stuff and maybe I lost some information. For now I don't use Git or SVN repository, but only a native configuration.
I have created a project using JHipster (Spring Boot) and bundled it with a .war file. The application is working fine when deployed to AWS EC2 instance.
Now the management wants me to deploy it on AWS Elastic Beanstalk and move all the configurations outside the .war file. For instance, The DB connection, email configuration, PayPal configuration not to be bundled with the .war file, whereas, it should load the properties from external resource like S3.
Can someone please help how can I change the application.yml and application-dev.yml etc to load values from some external source?
Take a look to Spring Cloud Config, which is initially meant to be used on spring cloud microservices, but can be used in order to solve your problem.
The approach here is, that in the early boot up phase your application connects to a spring cloud config server, to get external configuration. More on this, you can change several config properties, while your deployed application is running.
For the storage, cloud config enables git for production use case to store your configs, and I am pretty sure you can somehow use S3 for this...if needed.