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.
Related
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 !!
I tried to follow the new changes with the latests versions of Spring, where the bootstrap.yaml has been removed, and use the "spring.config.import" property, but I am not able to make my application work (discovery is working fine, but not config server). I am doing so many tries and errors, so it does not make so much sense to copy my current properties, but I will give all the details, so maybe someone is able to identify what is going on:
In my POM, there is already the next dependencies: "spring-cloud-starter-config", "spring-cloud-starter-consul-all", "spring-cloud-starter-consul-discovery" and "spring-cloud-starter-consul-config". Spring Cloud version is "2021.0.1" and Consul "3.1.0".
Main class annotated with #EnableDiscoveryClient
Using "application.properties-development", not YAML, and SPRING_PROFILES_ACTIVE=development
Application name is "profiles"
In my Consul instance, in the "Key / Value" section, I have the next structure: Consul Structure (/config/development/profiles and JSON with the properties to load).
It would be nice that, as with the Cloud Config Server, if no property file is found, it would allow me to run the application.
Thank you in advance.
Cheers!
I have a Spring Boot application for UI test automation using Cucumber and Selenium.
The application is expected to test multiple environments.
To begin with I have created json files with required properties like URLs, credentials etc. and load it(pass the file path as a property and use it) while triggering the test (mvn test -DconfigFile=config/env1_config.json).
I see that using profiles while running test is an option-Dspring.profiles.active=client1 but as i will configure multiple pipelines in Jenkins for testing multiple environments to use same project with different configuration files, it will clone the entire project and run tests in workspace corresponding to the pipeline. To avoid keeping multiple copies of the project, i am planning to use Rest API to trigger Selenium tests and have configuration files in Git.
Is it possible to create multiple application properties files with custom properties, place them in Git and use required property file in a Spring Boot application(inside a Rest API impl) based on a property or RequestParam using Spring Cloud Config or something?
you can use spring boot profiles and pass it as maven argument
just pass -Dspring.profiles.active=test1 as command line argument
you can read more here
You can do it by setting spring.profiles.active environment variable. Like if you are using property file for every environment by convention application-dev.properties, application-qa.properties. You can define you spring.profiles.active as dev and qa.
You can refer to the below link for more in site on same.
https://stackabuse.com/spring-boot-configuring-properties/
You can use Spring cloud server and client.
Make A project With Dependency Spring cloud server and make config file(appilcation.properties) there. For use that config file in other microservice
just add spring cloud cilent dependency in other projects and add this line in application.properties
spring.cloud.config.uri:[your spring cloud server project url]
refrence:-
spring cloud server:-
https://www.youtube.com/watch?v=gb1i4WyWNK4&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB&index=11
spring cloud client:- https://www.youtube.com/watch?v=E2HkL766VHs&list=PLqq-6Pq4lTTaoaVoQVfRJPqvNTCjcTvJB&index=12
Sharing the approach I ended up with as it might help someone someday.
As i wanted to create a Rest API and use properties from different config files in API implementation, based on the api request,
I created a Spring Cloud Config Server application that connects to application properties repo in git and I consumed Rest APIs exposed by Spring Cloud Config Server (host:port/app/profile) in the service layer of my Rest API implementation.
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.
While developing a springboot-liquibase application following this I need to specify the database username + password as liquibase.user and liquibase.password in the application.properties file. I am looking for a better secure way to use these parameter (dynamically fetched from some other place and use inside my java code)
Is there a way to achieve this?
There are couple of things you can do:
You can encrypt you properties file using jasypt-spring-boot. For more details have a look at demo app
If you are developing distributed system, then spring-cloud-config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments
Spring Cloud Config
This project allows you to use an external, centralized configuration repository for one or more applications. You don't need to rebuild your application if a property changes. You can simply change the property in your configuration repository and even push the changes to all of your applications.
See this Getting Started Guide.