- Notifications
You must be signed in to change notification settings - Fork0
coderdude1/SpringMicroSvcDemo_AccountWebClient
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project will setup and run a spring boot client facing webapp for account services. It will registerto a registration service, and will request an account microservice. This is the web client piece of amultiproject demo. At a minimum this will need to have the registration service project and theAccountService_Demo to demonstrate this usage of the microservice
This is an evolution of a springblog post on microservices with spring. The original source ishere and provides a great overview of thesepieces and how they work.
I ended up splitting up the original project that had three tiers (registration server, account micro service, andthe client webservice) into three separate projects. This allowed me to inject the spring config service.This requires the use of the bootstrap.yml to set the properties, and each app needs to be set separately.
Spring boot by default will use local configs are located in /resources. The first place isboostrap.[yml, properties]. This is a place to 'bootstrap' the spring context before it gets fired up.The other is by convention (app-name).[yml, properties]. Springboot is configured to use this filevia a -D property via an environment variable, or in the springboot app file(look in WebServer.java).The property name is 'spring.config.name', and in this app the value is 'web-server'. It can be a .ymlor a .properties file.
This app is set up to use either a local config or using 2 different spring config server as a demo. Detailsfollow.
Make sure everything in the /resources/bootstrap.yml are commented out. Make sure thateverything in /resources/web-server.yml are uncommented. An interesting note is the localconfig is configured to host this app on port 3333. The 2 spring configs loaded via the spring configserver specify different ports to show that the app is loading it's config remotely.
This is the url to see the webserver stuff it includes links for demoing the microservice callsand the beans that provide various metrics and such
Make sure everything in /resources/bootstrap.yml is uncommented, and everything in /resourcs/web-server.ymlare commented out. Note the port in use will now be spring 3334. You will need to make sure you are running theSpringConfigServer_Micro project, and have a gitrepo that contains the various config files (TBD)
There are two options for config when using the spring config server. The first demo's the default, ie no profile.The second shows the use of a profile (called 'alt'). In the local bootstrap.ymlthere is a property called profile with a value called 'alt'. When this is uncommented, it will ask for a differentconfig, which has a default port of 3335.
spring.cloud.config.failFast=true Set this to false if we want to keep trying to find it, willnoise up logs. Default is 'false'. I was getting errors in the netflix server, and this made that errorgo away but another one pop up
spring.cloud.config.failFast=true and we need to add the following to our maven deps
- spring-retry
- spring-boot-starter-aop
This will give us a default of 6 times for attempting to retry then die. The default behaviouris to retry 6 times with an initial backoff interval of 1000ms and an exponential multiplierof 1.1 for subsequent backoffs. You can configure these properties (and others) usingspring.cloud.config.retry.* configuration properties.
The Config Service serves property sources from /{name}/{profile}/{label}, where the defaultbindings in the client app are
"name" = ${spring.application.name}"profile" = ${spring.profiles.active} (actually Environment.getActiveProfiles())"label" = "master" - looks like a branch to useAll of them can be overridden by setting spring.cloud.config.* (where * is "name", "profile"or "label"). The "label" is useful for rolling back to previous versions of configuration;with the default Config Server implementation it can be a git label, branch name or commitid. Label can also be provided as a comma-separated list, in which case the items in the list are tried on-by-one until one succeeds. This can be useful when working on a feature branch, for instance, when you might want to align the config label with your branch, but make it optional (e.g. spring.cloud.config.label=myfeature,develop).
I have an web-server-alt.yml option in the config server, with http port 3335 to show specifyinga profile.
You can specify more than one profile, via comma sepearted list
The rest template that is used to access the Account microservice has some cool stuff going on. The springcloud ribbon artifact will inject a custom request factory that will interact with the registration service.You inject a service name as part of the URLhttp://ACCOUNT-SERVICE. Ribbon also provides an option forclient side load balancing (I will add an example of that later).
Look in WebAccountsService.demoOnly() (put a breakpoint and observe during startup the type of connectionfactory that gets injected)
Spring boot will provide a set of urls for various metrics and status checks (typically in JSON format). These can be disabled, and itlooks like for at least some of these can have a custom handler to provide app specific info. go tourl list.this is a listof all of them (there are a lot, including these
- /beans - list all the spring beans in the context
- /env - list the environment values
- /health - list the health of the app. there is a callback interface you can override to add custome behavior
- /metrics - various JVM stats
- /trace - Displays trace information (by default the last few HTTP requests).
- /info - Displays arbitrary application info. I think this can be overridden
- /flyway - list flyway migrations (doesn't work, not sure why, probably needs a config or impl)
- /autoconfig - Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied.
- /actuator - Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath.
- Orignal sourceMicroservices with spring
- Ngnix article
- Configuring It All Out" or "12-Factor App-Style Configuration with Spring"
- Spring Cloud Netflix
- Microservices With Spring
- Microservice Registration and Discovery with Spring Cloud and Netflix's Eureka
- Spring cloud samples git repo
- Configuring it all git repo
About
Resources
Uh oh!
There was an error while loading.Please reload this page.