eureka:
- instance:
- metadataMap:
- instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
-diff --git a/spring-cloud.html b/spring-cloud.html index 3639d6c..6215503 100644 --- a/spring-cloud.html +++ b/spring-cloud.html @@ -437,7 +437,6 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
org.springframework.cloud:spring-cloud-starter. There is also a
-parent pom and BOM (spring-cloud-starter-parent) for Maven users and a
+parent pom and BOM (spring-cloud-starters) for Maven users and a
Spring IO version management properties file for Gradle and Spring CLI
users. Example Maven configuration:
@@ -670,7 +668,7 @@ users. Example Maven configuration:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-parent</artifactId>
+ <artifactId>spring-cloud-starters</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
@@ -1048,16 +1046,6 @@ can change its co-ordinates, as long as Eureka is a fixed point.
In some cases, it may be desirable to fail startup of a service if
-it cannot connect to the Config Server. If this is the desired
-behavior, set the bootstrap configuration property
-spring.cloud.config.failFast=true and the client will halt with
-an Exception.
The application will listen for an EnvironmentChangedEvent and react
@@ -1129,25 +1117,6 @@ target cache. There is also a refresh(String) method to refresh an
individual bean by name. This functionality is exposed in the
/refresh endpoint (over HTTP or JMX).
|
- Note
- |
-
-@RefreshScope works (technically) on an @Configuration
-class, but it might lead to surprising behaviour: e.g. it does not
-mean that all the @Beans defined in that class are themselves
-@RefreshScope. Specifically, anything that depends on those beans
-cannot rely on them being updated when a refresh is initiated, unless
-it is itself in @RefreshScope (in which it will be rebuilt on a
-refresh and its dependencies re-injected, at which point they will be
-re-initialized from the refreshed @Configuration).
- |
-
Service Discovery is one of the key tenets of a microservice based architecture. Trying to hand configure each client or some form of convention can be very difficult to do and can be very brittle. Eureka is the Netflix Service Discovery Server and Client. The server can be configured and deployed to be highly available, with each server replicating state about the registered services to the others.
When a client registers with Eureka, it provide meta-data about itself -such as host and port, health indicator URL, home page etc. Eureka -receives heartbeat messages from each instance belonging to a service. -If the heartbeat fails over a configurable timetable, the instance is -normally removed from the registry.
+When clients register with Eureka, they provide eureka with meta-data about themselves such as host and port, health indicator URL, home page etc. Eureka receives heartbeat messages from each instance belonging to a service. If the heartbeat fails over a configurable timetable, the instance is normally removed from Eureka.
Example eureka client:
@@ -1546,22 +1509,6 @@ ID, or VIP).See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.
By default a eureka instance is registered with an ID that is equal to its host name (i.e. only one service per host). Using Spring Cloud you can override this by providing a unique identifier in eureka.instance.metadataMap.instanceId. For example:
eureka:
- instance:
- metadataMap:
- instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
-Spring Cloud has created an embedded Zuul proxy to ease the -development of a very common use case where a UI application wants to -proxy calls to one or more back end services. This feature is useful -for a user interface to proxy to the backend services it requires, -avoiding the need to manage CORS and authentication concerns -independently for all the backends.
+Spring Cloud has created an embedded Zuul proxy to ease the development of a very common use case where a UI application wants to proxy calls to one or more back end services. To enable it, annotate a Spring Boot main class with @EnableZuulProxy. This forwards local calls to /proxy/* to the appropriate service. The proxy uses Ribbon to locate an instance to forward to via Eureka. Forwarding to the service is protected by a Hystrix circuit breaker. Rules are configured via the Spring environment. The Config Server is an ideal place for the Zuul configuration. Zuul Embedded Proxy configuration rules look like the following:
zuul.proxy.route.users: /users+
To enable it, annotate a Spring Boot main class with
-@EnableZuulProxy, and this forwards local calls to the appropriate
-service. By convention, a service with the Eureka ID "users", will
-receive requests from the proxy located at /users (with the prefix
-stripped). The proxy uses Ribbon to locate an instance to forward to
-via Eureka, and all requests are executed in a hystrix command, so
-failures will show up in Hystrix metrics, and once the circuit is open
-the proxy will not try to contact the service.
This means that http calls to /proxy/users get forwarded to the users service. This proxy configuration is useful for services that host a user interface to proxy to the backend services it requires. By default, the proxy mapping gets stripped from the request before forwarding.
+Spring Cloud has created a standalone Zuul server. To enable it, annotate a Spring Boot main class with @EnableZuulServer. This routes all calls to the appropriate service. The server uses Ribbon to locate an instance to forward to via Eureka. Forwarding to the service is protected by a Hystrix circuit breaker. Rules are configured via the Spring environment. The Config Server is an ideal place for the Zuul configuration. Zuul Server configuration rules look like the following:
zuul.server.route.users: /users+
To skip having a service automatically added, set
-zuul.ignored-services to a list of service ids. To augment or change
-the proxy routes, you can add external configuration like the
-following:
This means that http calls to /users get forwarded to the users service.
+Since zuul, by default, intercepts all requests (/*), to enable actuator, you should set the management.port.
To use the Spring Boot error facilities while using the standalone Zuul server, please set the following properties
zuul:
- routes:
- users: /myusers/**
+# moves the Spring Dispatch Servlet to a path below `/`
+server:
+ servletPath: /app
+# sets the error path to use the Dispatch Servlet to resolve the error view
+error:
+ path: ${server.servletPath}/error
This means that http calls to "/myusers" get forwarded to the "users" -service (for example "/myusers/101" is forwarded to "/101").
-To get more fine-grained control over a route you can specify the path -and the serviceId independently:
- zuul:
- routes:
- users:
- path: /myusers/**
- serviceId: users_service
-This means that http calls to "/myusers" get forwarded to the -"users_service" service. The route has to have a "path" which can be -specified as an ant-style pattern, so "/myusers/" only matches one -level, but "/myusers/*" matches hierarchically.
-The location of the backend can be specified as either a "serviceId" -(for a Eureka service) or a "url" (for a physical location), e.g.
- zuul:
- routes:
- users:
- path: /myusers/**
- url: http://example.com/users_service
-To add a prefix to all mappings, set zuul.prefix to a value, such as
-/api. The proxy prefix is stripped from the request before the
-request is forwarded by default (switch this behaviour off with
-zuul.stripPrefix=false). You can also switch off the stripping of
-the service-specific prefix from individual routes, e.g.
zuul:
- routes:
- users:
- path: /myusers/**
- stripPrefix: false
-In this example requests to "/myusers/101" will be forwarded to "/myusers/101" on the "users" service.
-The X-Forwarded-Host header added to the forwarded requests by
-default. To turn it off set zuul.addProxyHeaders = false. The
-prefix path is stripped by default, and the request to the backend
-picks up a header "X-Forwarded-Prefix" ("/myusers" in the examples
-above).
An application with the @EnableZuulProxy could act as a standalone
-server if you set a default route ("/"), for example zuul.route.home:
-/ would route all traffic (i.e. "/**") to the "home" service.
tokenUri or authorizationUriclientId and clientSecret if it isn’t using the
tokenInfoUri (i.e. if it has jwt.* or userInfoUri).
By default all your endpoints are protected (i.e. "/") but you can
-pick and choose by adding a ResourceServerConfigurerAdapter (standard
-Spring OAuth feature), e.g. to protect only the "/api/" resources
@RestController
-@EnableOAuth2Resource
-class Application extends ResourceServerConfigurerAdapter {
-
- @Override
- public void configure(HttpSecurity http) throws Exception {
- http.requestMatchers()
- .antMatchers("/api/**")
- .and()
- .authorizeRequests()
- .anyRequest().authenticated();
- }
-
- @RequestMapping('/api')
- String home() {
- 'Hello World'
- }
-
-}
-