Consider a scenario: MasterApp( microservice 1) needs to call AssistApp( Microservice 2) to get data set A and tertiaryApp ( microservice 3) to get data set B.
Each `Microservice ( 2 and 3) has 3 instance which needs to be load balanced( Ribbon is getting used for client side load balancing).
Can you please let me know How should I prepare application.properties. I cannot put all 6 instance under property list of servers .
I have searched google( Dzone, nginx, spring examples in github and other forums), for a while but I was not able to find a conclusion for this Scenario.
Generally, you shouldn't config anything in application.properties.
I think you already have a param spring.application.name in your application.properties. And also, you have register your application into Eureka.
Then your call should be :
restTemplate.getForObject("http://SERVICE_NAME/xx/yy")
You don't need care about your 3 instance ip/port, just keep them the same application name.
Also, you should consider Feign, it will more convinced for your requirement.
Related
I have 3 microservices on my server Customer, Order and Shipping. I want these 3 services to use the same configuration from the config server. According to the spring cloud document, they said that
The HTTP service has resources in the form:
/secret/{**application**}/{profile}
/secret/{**application**}
/secret/{**defaultContext**}/{profile}
/secret/{**defaultContext**}
where the "application" is injected as the **spring.application.name** in the SpringApplication
so If I want these 3 services to use the same configuration I may have 2 options either use the same spring.application.name, which I don't want to do that, or create a configuration file for each service. It would be nice if I can use the same configuration file for every services since it's easy to maintain and update. Is it possible to do that?
update:
I may need to improve my searching skill lol. I found this document that provides an example on how to do that. Basically, all you need to do is to name the configuration file as application and it will be available to every services.
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#spring-cloud-config-server-vault-server
Supposed we had a couple of services service-1,service-2, service-3, we can handle global configurations like DB configs,environment configs etc using an externalized service like spring cloud config server or consul. But what is the best way to handle admin related settings in Micro-services e.g Max funding amount, vat, transaction limit etc setting that don't need a programmer to change ? note multiple services can use these values.
one way of doing this would be creating a bean which loads the data at the start of the app from db. In db you can have a table with admin privileges provide simple insert/update queries to the user who can/wants execute them. This user can be admin of the app who is using your app.
Other way would be creating your own properties/attributes and providing them in application.properties file. You can load those properties any of the beans which you think will need them.
eg (for spring boot):-
spring.max.transaction.limit -- in application.poperties
#Value("${spring.max.transaction.limit}")
private String transactionLimit; -- in the bean
This question is similar to (but different in the aim): Shared Config(at git) between SPring Boot Services so I will make use of the example the OP wrote there.
In my case I am using Spring Cloud Config Server with the Vault as backend, but for the sake of argument I will describe it as if it were in git. So imagine I have 4 Services: A, B, C and D.
And I have the following configs:
- A-prod.properties
- A-dev.properties
- B-prod.properties
- B-dev.properties
- C-prod.properties
- C-dev.properties
- D-prod.properties
- D-dev.properties
- application-prod.properties
- application-dev.properties
Now according to the docs I will have one of the services, let's say Service C getting his properties from C-(ENV).properties as well as application-(ENV).properties. Similarly the same with the others, i.e. everyone gets their own file and everything on application.properties.
My question is:
Is it possible to have for example a "semi-global" shared properties, e.g. a file that A and C share some config and another that B and D share some config?
An usage example would be DB Connection Credentials, where two services make use of one set of credentials, and the others another one.
I have been trying to find infos about this and doing some tests, but nothing that got me anywhere...
Unfortunately, it's not possible to achieve what you want. The only way to share properties is by using the application.properties(yml) file which is merged to every other configuration file.
I am new to spring boot, have come across a situation...
l have 10 different property files based on various logical modules of a monolith application(db.properties,jms.properties, etc) and 7 envs(pre, sit1,sit2,uat1,uat2,prod, dr). The idea of having diffrent property files so that we can use them almost with no change whenever we move to microservice based approach.
One approach says - we use various spring application names
like - spring.application.name=db,jms,a,b .....
In this way we will land up having 10×7 = 70 files under same folde? (In order to make it profile driven) like jms.properties,jms-dev.properties,jms-uat.propetris...... for all various logical modules.
Is there any better approach to host the files using config server?
We have a monolith application and we plan to continue the same for the time being.
I am struggling to build such facility using spring cloud config server...if any one can help
I have a REST web service exposed at http://server:8080/my-production-ws by JBoss (7). My spring (3.2) configuration has a datasource which points to a my-production-db database. So far so good.
I want to test that web service from the client side, including PUT/POST operations but I obviously don't want my tests to affect the production database.
Is there an easy way to have spring auto-magically create another web service entry point at http://server:8080/my-test-ws or maybe http://server:8080/my-production-ws/test that will have the exact same semantics as the production web service but will use a my-test-db database as a data source instead of my-production-db?
If this is not possible, what is the standard approach to integration testing in that situation?
I'd rather not duplicate every single method in my controllers.
Check the spring Profiles functionality, this should solve the problem. With it its possible to create two datasources with the same bean name in different profiles and then activate only one depending on a parameter passed to the the JVM.