I have a repository containing config properties that a Java Spring Cloud Config Server accesses whenever another Java Spring App requests to pull the properties. I want to have the same concept, but with a Python app that pulls similar properties. I know there's Python Spring libraries out there, but I can't find an example of Python pulling these properties from a similar config server.
In my case I have achieved this using spring-config-client library. I am sharing the code sample.
from spring_config.client import SpringConfigClient
config = (
ClientConfigurationBuilder()
.app_name("dashboard-service-python11") #config file
.address("http://localhost:3051")
.build()
)
c = SpringConfigClient(config)
c.get_config()
print(c.get_config())
Related
I know how to read AWS credentials (for one environment) through application properties.
I need to create multiple amazonSnsClient() through application properties on application startup.
I have an application properties file that has AWS properties of multiple environments in one file which looks like below example
#DEV
abc.env[0].aws.accessKeyId=xaw
abc.env[0].aws.awsSecretKeyId=yrt
#TEST
abc.env[1].aws.accessKeyId=abc
abc.env[1].aws.awsSecretKeyId=def
I will have a HashMap that will contain all the AWS credentials from a properties file.
I need to read all the AWS Credentials from a properties file and create that many amazonSnsClient
How can I achieve the same in Spring boot? Is there any annotation that I can make use of?
Note: The requirement is that the properties of Dev and Test have to be in one file
Can someone please help?
Thank you for your time.
You create the client manually like this ...
var client = SnsClient.builder()
.region(Region.of(awsProperties.getRegion()))
.withCredentials(... add your credentials here)
.build();
// use client methods to interact with AWS
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.
Am trying spring cloud config server and client as stand-alone separate applications.
on git, i have folder structure like below-
my-config
----projectfolder1
--------application.properties
----projectfolder2
--------application.properties
I would like that spring cloud client named "projectfolder1" should search application.properties within projectfolder1 on git from spring cloud server i.e
----projectfolder1
--------application.properties
and client "projectfolder2" should get the below mentioned properties from spring cloud config server
----projectfolder2
--------application.properties
My Spring Cloud Config server application.properties has-
spring.cloud.config.server.git.search-paths='{application}'
projectfolder1 in its bootstrap.properties has
spring.application.name=projectfolder1
and projectfolder2 in its bootstrap.properties has
spring.application.name=projectfolder2
According to spring cloud config documentation '{application}' in search path should find the files within the "resolved application name" folder on git. But the above '{application}' doesn't work for me. Clients projectfolder1 and projectfolder2 are not able to get any property at all.
pls assist. i know its possible duplicate of another question on stack overflow. but that question is not resolved and i do not have rights to comment on any question being a new user, So i created this as another question here.
I solved it myself.
The trick is to give search-path {application} without quotes as given below.
It was a little tricky as spring documentation mentions it as '{application}' , probably spring developers just wanted to highlight it with quotes.
spring.cloud.config.server.git.search-paths={application}
instead of
spring.cloud.config.server.git.search-paths='{application}'
I am using Spring cloud config server with GIT which is working fine as expected.
Now, my requirement is to get the list of filenames from the spring cloud server.
Spring cloud config only provides API like http://localhost:8088/myconfig/default/master/config.properties to get the property values.
Is there any API available to get all file names? If not, what would be the alternate approach?
No, unfortunately it's not possible. The way we did in our project - added properties with needed file names in config.properties and fetched files in the code using
additional endpoint at /{name}/{profile}/{label}/{path}
https://cloud.spring.io/spring-cloud-config/reference/html/#_serving_plain_text
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.