Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

coderdude1/SpringMicroSvcDemo_AccountWebClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

Account Web Client

Configuration

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.

Local config

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

Spring Config Server

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 config client options

Fail if we can't talk to the config server

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

Retry config if we can't talk to the config server

spring.cloud.config.failFast=true and we need to add the following to our maven deps

  1. spring-retry
  2. 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.

Specifying what config to ask for.

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 use

All 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

How a remote service is wired into the client

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 Web Default URL's

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

  1. /beans - list all the spring beans in the context
  2. /env - list the environment values
  3. /health - list the health of the app. there is a callback interface you can override to add custome behavior
  4. /metrics - various JVM stats
  5. /trace - Displays trace information (by default the last few HTTP requests).
  6. /info - Displays arbitrary application info. I think this can be overridden
  7. /flyway - list flyway migrations (doesn't work, not sure why, probably needs a config or impl)
  8. /autoconfig - Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied.
  9. /actuator - Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath.

Interesting URLS

  1. Orignal sourceMicroservices with spring
  2. Ngnix article
  3. Configuring It All Out" or "12-Factor App-Style Configuration with Spring"
  4. Spring Cloud Netflix
  5. Microservices With Spring
  6. Microservice Registration and Discovery with Spring Cloud and Netflix's Eureka
  7. Spring cloud samples git repo
  8. Configuring it all git repo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp