diff --git a/1.3.x/multi/multi__circuit_breaker_hystrix_clients.html b/1.3.x/multi/multi__circuit_breaker_hystrix_clients.html index 9d3619c0b..53fa3e411 100644 --- a/1.3.x/multi/multi__circuit_breaker_hystrix_clients.html +++ b/1.3.x/multi/multi__circuit_breaker_hystrix_clients.html @@ -1,7 +1,7 @@ - 3. Circuit Breaker: Hystrix Clients

3. Circuit Breaker: Hystrix Clients

Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.

Figure 3.1. Microservice Graph

HystrixGraph

A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service is greater than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failue percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit a fallback can be provided by the developer.

Figure 3.2. Hystrix fallback prevents cascading failures

HystrixFallback

Having an open circuit stops cascading failures and allows overwhelmed or failing services time to heal. The fallback can be another Hystrix protected call, static data or a sane empty value. Fallbacks may be chained so the first fallback makes some other business call which in turn falls back to static data.

3.1 How to Include Hystrix

To include Hystrix in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page + 3. Circuit Breaker: Hystrix Clients

3. Circuit Breaker: Hystrix Clients

Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.

Figure 3.1. Microservice Graph

HystrixGraph

A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service is greater than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failue percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit a fallback can be provided by the developer.

Figure 3.2. Hystrix fallback prevents cascading failures

HystrixFallback

Having an open circuit stops cascading failures and allows overwhelmed or failing services time to heal. The fallback can be another Hystrix protected call, static data or a sane empty value. Fallbacks may be chained so the first fallback makes some other business call which in turn falls back to static data.

3.1 How to Include Hystrix

To include Hystrix in your project use the starter with group org.springframework.cloud +and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

Example boot app:

@SpringBootApplication
 @EnableCircuitBreaker
 public class Application {
diff --git a/1.3.x/multi/multi__external_configuration_archaius.html b/1.3.x/multi/multi__external_configuration_archaius.html
index 483ac98fd..4f9141416 100644
--- a/1.3.x/multi/multi__external_configuration_archaius.html
+++ b/1.3.x/multi/multi__external_configuration_archaius.html
@@ -1,6 +1,6 @@
 
       
-   8. External Configuration: Archaius

8. External Configuration: Archaius

Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties.

Archaius Example.  + 8. External Configuration: Archaius

8. External Configuration: Archaius

Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties.

Archaius Example. 

class ArchaiusTest {
     DynamicStringProperty myprop = DynamicPropertyFactory
             .getInstance()
diff --git a/1.3.x/multi/multi__hystrix_timeouts_and_ribbon_clients.html b/1.3.x/multi/multi__hystrix_timeouts_and_ribbon_clients.html
index a27ce3b8a..84cc4fc20 100644
--- a/1.3.x/multi/multi__hystrix_timeouts_and_ribbon_clients.html
+++ b/1.3.x/multi/multi__hystrix_timeouts_and_ribbon_clients.html
@@ -5,14 +5,14 @@ is configured to be longer than the configured Ribbon timeout, including any pot
 retries that might be made.  For example, if your Ribbon connection timeout is one second and
 the Ribbon client might retry the request three times, than your Hystrix timeout should
 be slightly more than three seconds.

5.1 How to Include Hystrix Dashboard

To include the Hystrix Dashboard in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page +and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

To run the Hystrix Dashboard annotate your Spring Boot main class with @EnableHystrixDashboard. You then visit /hystrix and point the dashboard to an individual instances /hystrix.stream endpoint in a Hystrix client application.

[Note]Note

When connecting to a /hystrix.stream endpoint which uses HTTPS the certificate used by the server must be trusted by the JVM. If the certificate is not trusted you must import the certificate into the JVM in order for the Hystrix Dashboard to make a successful connection to the stream endpoint.

5.2 Turbine

Looking at an individual instances Hystrix data is not very useful in terms of the overall health of the system. Turbine is an application that aggregates all of the relevant /hystrix.stream endpoints into a combined /turbine.stream for use in the Hystrix Dashboard. Individual instances are located via Eureka. Running Turbine is as simple as annotating your main class with the @EnableTurbine annotation (e.g. using spring-cloud-starter-turbine to set up the classpath). All of the documented configuration properties from the Turbine 1 wiki apply. The only difference is that the turbine.instanceUrlSuffix does not need the port prepended as this is handled automatically unless turbine.instanceInsertPort=false.

[Note]Note

By default, Turbine looks for the /hystrix.stream endpoint on a registered instance by looking up its homePageUrl entry in Eureka, then appending /hystrix.stream to it. This means that if spring-boot-actuator is running on its own port (which is the default), the call to /hystrix.stream will fail. To make turbine find the Hystrix stream at the correct port, you need to add management.port to the instances' metadata:

eureka:
   instance:
     metadata-map:
-      management.port: ${management.port:8081}

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: http://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
+      management.port: ${management.port:8081}

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: https://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
   aggregator:
     clusterConfig: CUSTOMERS
   appConfig: customers

The clusterName can be customized by a SPEL expression in turbine.clusterNameExpression with root an instance of InstanceInfo. The default value is appName, which means that the Eureka serviceId ends up as the cluster key (i.e. the InstanceInfo for customers has an appName of "CUSTOMERS"). A different example would be turbine.clusterNameExpression=aSGName, which would get the cluster name from the AWS ASG name. Another example:

turbine:
diff --git a/1.3.x/multi/multi__polyglot_support_with_sidecar.html b/1.3.x/multi/multi__polyglot_support_with_sidecar.html
index abd168b7e..88e6a0ed4 100644
--- a/1.3.x/multi/multi__polyglot_support_with_sidecar.html
+++ b/1.3.x/multi/multi__polyglot_support_with_sidecar.html
@@ -56,7 +56,7 @@ Non-jvm app can access the customer service via configserver
 and the Sidecar is on port 5678, then it can be accessed at
 http://localhost:5678/configserver

Non-jvm app can take advantage of the Config Server’s ability to return YAML -documents. For example, a call to http://sidecar.local.spring.io:5678/configserver/default-master.yml +documents. For example, a call to https://sidecar.local.spring.io:5678/configserver/default-master.yml might result in a YAML document like the following

eureka:
   client:
     serviceUrl:
diff --git a/1.3.x/multi/multi__router_and_filter_zuul.html b/1.3.x/multi/multi__router_and_filter_zuul.html
index d5b110d23..cd5a9e392 100644
--- a/1.3.x/multi/multi__router_and_filter_zuul.html
+++ b/1.3.x/multi/multi__router_and_filter_zuul.html
@@ -1,7 +1,7 @@
 
       
-   9. Router and Filter: Zuul

9. Router and Filter: Zuul

Routing in an integral part of a microservice architecture. For example, / may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul is a JVM based router and server side load balancer by Netflix.

Netflix uses Zuul for the following:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

Zuul’s rule engine allows rules and filters to be written in essentially any JVM language, with built in support for Java and Groovy.

[Note]Note

The configuration property zuul.max.host.connections has been replaced by two new properties, zuul.host.maxTotalConnections and zuul.host.maxPerRouteConnections which default to 200 and 20 respectively.

[Note]Note

Default Hystrix isolation pattern (ExecutionIsolationStrategy) for all routes is SEMAPHORE. zuul.ribbonIsolationStrategy can be changed to THREAD if this isolation pattern is preferred.

9.1 How to Include Zuul

To include Zuul in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page + 9. Router and Filter: Zuul

9. Router and Filter: Zuul

Routing in an integral part of a microservice architecture. For example, / may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul is a JVM based router and server side load balancer by Netflix.

Netflix uses Zuul for the following:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

Zuul’s rule engine allows rules and filters to be written in essentially any JVM language, with built in support for Java and Groovy.

[Note]Note

The configuration property zuul.max.host.connections has been replaced by two new properties, zuul.host.maxTotalConnections and zuul.host.maxPerRouteConnections which default to 200 and 20 respectively.

[Note]Note

Default Hystrix isolation pattern (ExecutionIsolationStrategy) for all routes is SEMAPHORE. zuul.ribbonIsolationStrategy can be changed to THREAD if this isolation pattern is preferred.

9.1 How to Include Zuul

To include Zuul in your project use the starter with group org.springframework.cloud +and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

9.2 Embedded Zuul Reverse Proxy

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 @@ -48,7 +48,7 @@ level, but "/myusers/**" matches hierarchically.

The location of the backe routes: users: path: /myusers/** - url: http://example.com/users_service

+ url: https://example.com/users_service

These simple url-routes don’t get executed as a HystrixCommand nor can you loadbalance multiple URLs with Ribbon. To achieve this, specify a service-route and configure a Ribbon client for the serviceId (this currently requires disabling Eureka support in Ribbon: @@ -187,7 +187,7 @@ but redirect some of the requests to new ones.

Example configuration:

< routes: first: path: /first/** - url: http://first.example.com + url: https://first.example.com second: path: /second/** url: forward:/second @@ -196,7 +196,7 @@ but redirect some of the requests to new ones.

Example configuration:

< url: forward:/3rd legacy: path: /** - url: http://legacy.example.com

+ url: https://legacy.example.com

In this example we are strangling the "legacy" app which is mapped to all requests that do not match one of the other patterns. Paths in /first/** have been extracted into a new service with an external diff --git a/1.3.x/multi/multi__service_discovery_eureka_clients.html b/1.3.x/multi/multi__service_discovery_eureka_clients.html index c972e4455..47bad9b23 100644 --- a/1.3.x/multi/multi__service_discovery_eureka_clients.html +++ b/1.3.x/multi/multi__service_discovery_eureka_clients.html @@ -1,7 +1,7 @@ 1. Service Discovery: Eureka Clients

1. Service Discovery: Eureka Clients

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.

1.1 How to Include Eureka Client

To include Eureka Client in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

1.2 Registering with Eureka

When a client registers with Eureka, it provides 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. @@ -40,7 +40,7 @@ registry to locate other services). The instance behaviour is driven by eureka.instance.* configuration keys, but the defaults will be fine if you ensure that your application has a spring.application.name (this is the default for the Eureka service -ID, or VIP).

See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.

1.3 Authenticating with the Eureka Server

HTTP basic authentication will be automatically added to your eureka +ID, or VIP).

See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.

1.3 Authenticating with the Eureka Server

HTTP basic authentication will be automatically added to your eureka client if one of the eureka.client.serviceUrl.defaultZone URLs has credentials embedded in it (curl style, like http://user:password@localhost:8761/eureka). For more complex needs @@ -105,7 +105,7 @@ implementing your own com.netflix.appinfo.HealthCheckHandl instance: hostname: ${vcap.application.uris[0]} nonSecurePort: 80

-

Depending on the way the security rules are set up in your Cloudfoundry instance, you might be able to register and use the IP address of the host VM for direct service-to-service calls. This feature is not (yet) available on Pivotal Web Services (PWS).

1.7.2 Using Eureka on AWS

If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way:

@Bean
+

Depending on the way the security rules are set up in your Cloudfoundry instance, you might be able to register and use the IP address of the host VM for direct service-to-service calls. This feature is not (yet) available on Pivotal Web Services (PWS).

1.7.2 Using Eureka on AWS

If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way:

@Bean
 @Profile("!default")
 public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
   EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
diff --git a/1.3.x/multi/multi_spring-cloud-eureka-server.html b/1.3.x/multi/multi_spring-cloud-eureka-server.html
index 05f926ca1..c693e9d47 100644
--- a/1.3.x/multi/multi_spring-cloud-eureka-server.html
+++ b/1.3.x/multi/multi_spring-cloud-eureka-server.html
@@ -1,7 +1,7 @@
 
       
    2. Service Discovery: Eureka Server

2. Service Discovery: Eureka Server

2.1 How to Include Eureka Server

To include Eureka Server in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

2.2 How to Run a Eureka Server

Example eureka server;

@SpringBootApplication
 @EnableEurekaServer
 public class Application {
diff --git a/1.3.x/multi/multi_spring-cloud-feign.html b/1.3.x/multi/multi_spring-cloud-feign.html
index 3a0e8ea5d..430baa1a7 100644
--- a/1.3.x/multi/multi_spring-cloud-feign.html
+++ b/1.3.x/multi/multi_spring-cloud-feign.html
@@ -1,7 +1,7 @@
 
       
    7. Declarative REST Client: Feign

7. Declarative REST Client: Feign

Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.

7.1 How to Include Feign

To include Feign in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page +and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

Example spring boot app

@Configuration
 @ComponentScan
 @EnableAutoConfiguration
diff --git a/1.3.x/multi/multi_spring-cloud-ribbon.html b/1.3.x/multi/multi_spring-cloud-ribbon.html
index 1a019c2c9..d64584093 100644
--- a/1.3.x/multi/multi_spring-cloud-ribbon.html
+++ b/1.3.x/multi/multi_spring-cloud-ribbon.html
@@ -10,7 +10,7 @@ annotation). Spring Cloud creates a new ensemble as an
 ApplicationContext on demand for each named client using
 RibbonClientConfiguration. This contains (amongst other things) an
 ILoadBalancer, a RestClient, and a ServerListFilter.

6.1 How to Include Ribbon

To include Ribbon in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page +and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

6.2 Customizing the Ribbon Client

You can configure some bits of a Ribbon client using external properties in <client>.ribbon.*, which is no different than using the Netflix APIs natively, except that you can use Spring Boot diff --git a/1.3.x/single/spring-cloud-netflix.html b/1.3.x/single/spring-cloud-netflix.html index 6564f55b8..5888b4219 100644 --- a/1.3.x/single/spring-cloud-netflix.html +++ b/1.3.x/single/spring-cloud-netflix.html @@ -6,7 +6,7 @@ simple annotations you can quickly enable and configure the common patterns insi application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).

1. Service Discovery: Eureka Clients

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.

1.1 How to Include Eureka Client

To include Eureka Client in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

1.2 Registering with Eureka

When a client registers with Eureka, it provides 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. @@ -45,7 +45,7 @@ registry to locate other services). The instance behaviour is driven by eureka.instance.* configuration keys, but the defaults will be fine if you ensure that your application has a spring.application.name (this is the default for the Eureka service -ID, or VIP).

See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.

1.3 Authenticating with the Eureka Server

HTTP basic authentication will be automatically added to your eureka +ID, or VIP).

See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.

1.3 Authenticating with the Eureka Server

HTTP basic authentication will be automatically added to your eureka client if one of the eureka.client.serviceUrl.defaultZone URLs has credentials embedded in it (curl style, like http://user:password@localhost:8761/eureka). For more complex needs @@ -110,7 +110,7 @@ implementing your own com.netflix.appinfo.HealthCheckHandl instance: hostname: ${vcap.application.uris[0]} nonSecurePort: 80

-

Depending on the way the security rules are set up in your Cloudfoundry instance, you might be able to register and use the IP address of the host VM for direct service-to-service calls. This feature is not (yet) available on Pivotal Web Services (PWS).

1.7.2 Using Eureka on AWS

If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way:

@Bean
+

Depending on the way the security rules are set up in your Cloudfoundry instance, you might be able to register and use the IP address of the host VM for direct service-to-service calls. This feature is not (yet) available on Pivotal Web Services (PWS).

1.7.2 Using Eureka on AWS

If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way:

@Bean
 @Profile("!default")
 public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) {
   EurekaInstanceConfigBean b = new EurekaInstanceConfigBean(inetUtils);
@@ -175,7 +175,7 @@ the metadataMap property.  For example if zone 2 you would need to set the following Eureka properties in service 1

Service 1 in Zone 1

eureka.instance.metadataMap.zone = zone1
 eureka.client.preferSameZoneEureka = true

Service 1 in Zone 2

eureka.instance.metadataMap.zone = zone2
 eureka.client.preferSameZoneEureka = true

2. Service Discovery: Eureka Server

2.1 How to Include Eureka Server

To include Eureka Server in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

2.2 How to Run a Eureka Server

Example eureka server;

@SpringBootApplication
 @EnableEurekaServer
 public class Application {
@@ -262,8 +262,8 @@ separated (inside a data centre or between multiple data centres) then
 the system can in principle survive split-brain type failures.

2.6 Prefer IP Address

In some cases, it is preferable for Eureka to advertise the IP Adresses of services rather than the hostname. Set eureka.instance.preferIpAddress to true and when the application registers with eureka, it will use its -IP Address rather than its hostname.

3. Circuit Breaker: Hystrix Clients

Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.

Figure 3.1. Microservice Graph

HystrixGraph

A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service is greater than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failue percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit a fallback can be provided by the developer.

Figure 3.2. Hystrix fallback prevents cascading failures

HystrixFallback

Having an open circuit stops cascading failures and allows overwhelmed or failing services time to heal. The fallback can be another Hystrix protected call, static data or a sane empty value. Fallbacks may be chained so the first fallback makes some other business call which in turn falls back to static data.

3.1 How to Include Hystrix

To include Hystrix in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page +IP Address rather than its hostname.

3. Circuit Breaker: Hystrix Clients

Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.

Figure 3.1. Microservice Graph

HystrixGraph

A service failure in the lower level of services can cause cascading failure all the way up to the user. When calls to a particular service is greater than circuitBreaker.requestVolumeThreshold (default: 20 requests) and failue percentage is greater than circuitBreaker.errorThresholdPercentage (default: >50%) in a rolling window defined by metrics.rollingStats.timeInMilliseconds (default: 10 seconds), the circuit opens and the call is not made. In cases of error and an open circuit a fallback can be provided by the developer.

Figure 3.2. Hystrix fallback prevents cascading failures

HystrixFallback

Having an open circuit stops cascading failures and allows overwhelmed or failing services time to heal. The fallback can be another Hystrix protected call, static data or a sane empty value. Fallbacks may be chained so the first fallback makes some other business call which in turn falls back to static data.

3.1 How to Include Hystrix

To include Hystrix in your project use the starter with group org.springframework.cloud +and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

Example boot app:

@SpringBootApplication
 @EnableCircuitBreaker
 public class Application {
@@ -316,14 +316,14 @@ is configured to be longer than the configured Ribbon timeout, including any pot
 retries that might be made.  For example, if your Ribbon connection timeout is one second and
 the Ribbon client might retry the request three times, than your Hystrix timeout should
 be slightly more than three seconds.

5.1 How to Include Hystrix Dashboard

To include the Hystrix Dashboard in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page +and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

To run the Hystrix Dashboard annotate your Spring Boot main class with @EnableHystrixDashboard. You then visit /hystrix and point the dashboard to an individual instances /hystrix.stream endpoint in a Hystrix client application.

[Note]Note

When connecting to a /hystrix.stream endpoint which uses HTTPS the certificate used by the server must be trusted by the JVM. If the certificate is not trusted you must import the certificate into the JVM in order for the Hystrix Dashboard to make a successful connection to the stream endpoint.

5.2 Turbine

Looking at an individual instances Hystrix data is not very useful in terms of the overall health of the system. Turbine is an application that aggregates all of the relevant /hystrix.stream endpoints into a combined /turbine.stream for use in the Hystrix Dashboard. Individual instances are located via Eureka. Running Turbine is as simple as annotating your main class with the @EnableTurbine annotation (e.g. using spring-cloud-starter-turbine to set up the classpath). All of the documented configuration properties from the Turbine 1 wiki apply. The only difference is that the turbine.instanceUrlSuffix does not need the port prepended as this is handled automatically unless turbine.instanceInsertPort=false.

[Note]Note

By default, Turbine looks for the /hystrix.stream endpoint on a registered instance by looking up its homePageUrl entry in Eureka, then appending /hystrix.stream to it. This means that if spring-boot-actuator is running on its own port (which is the default), the call to /hystrix.stream will fail. To make turbine find the Hystrix stream at the correct port, you need to add management.port to the instances' metadata:

eureka:
   instance:
     metadata-map:
-      management.port: ${management.port:8081}

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: http://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
+      management.port: ${management.port:8081}

The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: https://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers":

turbine:
   aggregator:
     clusterConfig: CUSTOMERS
   appConfig: customers

The clusterName can be customized by a SPEL expression in turbine.clusterNameExpression with root an instance of InstanceInfo. The default value is appName, which means that the Eureka serviceId ends up as the cluster key (i.e. the InstanceInfo for customers has an appName of "CUSTOMERS"). A different example would be turbine.clusterNameExpression=aSGName, which would get the cluster name from the AWS ASG name. Another example:

turbine:
@@ -342,7 +342,7 @@ annotation). Spring Cloud creates a new ensemble as an
 ApplicationContext on demand for each named client using
 RibbonClientConfiguration. This contains (amongst other things) an
 ILoadBalancer, a RestClient, and a ServerListFilter.

6.1 How to Include Ribbon

To include Ribbon in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page +and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

6.2 Customizing the Ribbon Client

You can configure some bits of a Ribbon client using external properties in <client>.ribbon.*, which is no different than using the Netflix APIs natively, except that you can use Spring Boot @@ -430,7 +430,7 @@ This lazy loading behavior can be changed to instead eagerly load up these child enabled: true clients: client1, client2, client3

7. Declarative REST Client: Feign

Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations. Feign also supports pluggable encoders and decoders. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.

7.1 How to Include Feign

To include Feign in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page +and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

Example spring boot app

@Configuration
 @ComponentScan
 @EnableAutoConfiguration
@@ -593,7 +593,7 @@ feign.compression.request.min-request-size=2048return Logger.Level.FULL;
     }
-}

8. External Configuration: Archaius

Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties.

Archaius Example.  +}

8. External Configuration: Archaius

Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties.

Archaius Example. 

class ArchaiusTest {
     DynamicStringProperty myprop = DynamicPropertyFactory
             .getInstance()
@@ -603,8 +603,8 @@ feign.compression.request.min-request-size=2048

-

Archaius has its own set of configuration files and loading priorities. Spring applications should generally not use Archaius directly, but the need to configure the Netflix tools natively remains. Spring Cloud has a Spring Environment Bridge so Archaius can read properties from the Spring Environment. This allows Spring Boot projects to use the normal configuration toolchain, while allowing them to configure the Netflix tools, for the most part, as documented.

9. Router and Filter: Zuul

Routing in an integral part of a microservice architecture. For example, / may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul is a JVM based router and server side load balancer by Netflix.

Netflix uses Zuul for the following:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

Zuul’s rule engine allows rules and filters to be written in essentially any JVM language, with built in support for Java and Groovy.

[Note]Note

The configuration property zuul.max.host.connections has been replaced by two new properties, zuul.host.maxTotalConnections and zuul.host.maxPerRouteConnections which default to 200 and 20 respectively.

[Note]Note

Default Hystrix isolation pattern (ExecutionIsolationStrategy) for all routes is SEMAPHORE. zuul.ribbonIsolationStrategy can be changed to THREAD if this isolation pattern is preferred.

9.1 How to Include Zuul

To include Zuul in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page +

Archaius has its own set of configuration files and loading priorities. Spring applications should generally not use Archaius directly, but the need to configure the Netflix tools natively remains. Spring Cloud has a Spring Environment Bridge so Archaius can read properties from the Spring Environment. This allows Spring Boot projects to use the normal configuration toolchain, while allowing them to configure the Netflix tools, for the most part, as documented.

9. Router and Filter: Zuul

Routing in an integral part of a microservice architecture. For example, / may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul is a JVM based router and server side load balancer by Netflix.

Netflix uses Zuul for the following:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

Zuul’s rule engine allows rules and filters to be written in essentially any JVM language, with built in support for Java and Groovy.

[Note]Note

The configuration property zuul.max.host.connections has been replaced by two new properties, zuul.host.maxTotalConnections and zuul.host.maxPerRouteConnections which default to 200 and 20 respectively.

[Note]Note

Default Hystrix isolation pattern (ExecutionIsolationStrategy) for all routes is SEMAPHORE. zuul.ribbonIsolationStrategy can be changed to THREAD if this isolation pattern is preferred.

9.1 How to Include Zuul

To include Zuul in your project use the starter with group org.springframework.cloud +and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.

9.2 Embedded Zuul Reverse Proxy

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 @@ -651,7 +651,7 @@ level, but "/myusers/**" matches hierarchically.

The location of the backe routes: users: path: /myusers/** - url: http://example.com/users_service

+ url: https://example.com/users_service

These simple url-routes don’t get executed as a HystrixCommand nor can you loadbalance multiple URLs with Ribbon. To achieve this, specify a service-route and configure a Ribbon client for the serviceId (this currently requires disabling Eureka support in Ribbon: @@ -790,7 +790,7 @@ but redirect some of the requests to new ones.

Example configuration:

< routes: first: path: /first/** - url: http://first.example.com + url: https://first.example.com second: path: /second/** url: forward:/second @@ -799,7 +799,7 @@ but redirect some of the requests to new ones.

Example configuration:

< url: forward:/3rd legacy: path: /** - url: http://legacy.example.com

+ url: https://legacy.example.com

In this example we are strangling the "legacy" app which is mapped to all requests that do not match one of the other patterns. Paths in /first/** have been extracted into a new service with an external @@ -1126,7 +1126,7 @@ Non-jvm app can access the customer service via configserver and the Sidecar is on port 5678, then it can be accessed at http://localhost:5678/configserver

Non-jvm app can take advantage of the Config Server’s ability to return YAML -documents. For example, a call to http://sidecar.local.spring.io:5678/configserver/default-master.yml +documents. For example, a call to https://sidecar.local.spring.io:5678/configserver/default-master.yml might result in a YAML document like the following

eureka:
   client:
     serviceUrl:
diff --git a/1.3.x/spring-cloud-netflix.xml b/1.3.x/spring-cloud-netflix.xml
index 8a6cbe2af..e56349cc8 100644
--- a/1.3.x/spring-cloud-netflix.xml
+++ b/1.3.x/spring-cloud-netflix.xml
@@ -22,7 +22,7 @@ Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon).
 
How to Include Eureka Client To include Eureka Client in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
@@ -76,7 +76,7 @@ by eureka.instance.* configuration keys, but the defaults wil fine if you ensure that your application has a spring.application.name (this is the default for the Eureka service ID, or VIP). -See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options. +See EurekaInstanceConfigBean and EurekaClientConfigBean for more details of the configurable options.
Authenticating with the Eureka Server @@ -198,7 +198,7 @@ implementing your own com.netflix.appinfo.HealthCheckHandler.
Using Eureka on AWS -If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way: +If the application is planned to be deployed to an AWS cloud, then the Eureka instance will have to be configured to be AWS aware and this can be done by customizing the EurekaInstanceConfigBean the following way: @Bean @Profile("!default") public EurekaInstanceConfigBean eurekaInstanceConfig(InetUtils inetUtils) { @@ -310,7 +310,7 @@ eureka.client.preferSameZoneEureka = true
How to Include Eureka Server To include Eureka Server in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page +and artifact id spring-cloud-starter-eureka-server. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
@@ -445,7 +445,7 @@ IP Address rather than its hostname. Circuit Breaker: Hystrix Clients -Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls. +Netflix has created a library called Hystrix that implements the circuit breaker pattern. In a microservice architecture it is common to have multiple layers of service calls.
Microservice Graph @@ -469,7 +469,7 @@ IP Address rather than its hostname.
How to Include Hystrix To include Hystrix in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page +and artifact id spring-cloud-starter-hystrix. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train. Example boot app: @SpringBootApplication @@ -564,7 +564,7 @@ be slightly more than three seconds.
How to Include Hystrix Dashboard To include the Hystrix Dashboard in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page +and artifact id spring-cloud-starter-hystrix-dashboard. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train. To run the Hystrix Dashboard annotate your Spring Boot main class with @EnableHystrixDashboard. You then visit /hystrix and point the dashboard to an individual instances /hystrix.stream endpoint in a Hystrix client application. @@ -584,7 +584,7 @@ To make turbine find the Hystrix stream at the correct port, you need to add
  • -The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: http://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers": +The configuration key turbine.appConfig is a list of eureka serviceIds that turbine will use to lookup instances. The turbine stream is then used in the Hystrix dashboard using a url that looks like: https://my.turbine.sever:8080/turbine.stream?cluster=CLUSTERNAME (the cluster parameter can be omitted if the name is "default"). The cluster parameter must match an entry in turbine.aggregator.clusterConfig. Values returned from eureka are uppercase, thus we expect this example to work if there is an app registered with Eureka called "customers": turbine: aggregator: clusterConfig: CUSTOMERS @@ -629,7 +629,7 @@ annotation). Spring Cloud creates a new ensemble as an
    How to Include Ribbon To include Ribbon in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page +and artifact id spring-cloud-starter-ribbon. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
    @@ -833,7 +833,7 @@ This lazy loading behavior can be changed to instead eagerly load up these child
    How to Include Feign To include Feign in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page +and artifact id spring-cloud-starter-feign. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train. Example spring boot app @Configuration @@ -1166,7 +1166,7 @@ public class FooConfiguration { External Configuration: Archaius -Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties. +Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties. Archaius Example @@ -1186,7 +1186,7 @@ public class FooConfiguration { Router and Filter: Zuul Routing in an integral part of a microservice architecture. For example, / may be mapped to your web application, /api/users is mapped to the user service and /api/shop is mapped to the shop service. Zuul is a JVM based router and server side load balancer by Netflix. -Netflix uses Zuul for the following: +Netflix uses Zuul for the following: Authentication @@ -1229,7 +1229,7 @@ public class FooConfiguration {
    How to Include Zuul To include Zuul in your project use the starter with group org.springframework.cloud -and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page +and artifact id spring-cloud-starter-zuul. See the Spring Cloud Project page for details on setting up your build system with the current Spring Cloud Release Train.
    @@ -1306,7 +1306,7 @@ level, but "/myusers/**" matches hierarchically. routes: users: path: /myusers/** - url: http://example.com/users_service + url: https://example.com/users_service These simple url-routes don’t get executed as a HystrixCommand nor can you loadbalance multiple URLs with Ribbon. @@ -1525,7 +1525,7 @@ but redirect some of the requests to new ones. routes: first: path: /first/** - url: http://first.example.com + url: https://first.example.com second: path: /second/** url: forward:/second @@ -1534,7 +1534,7 @@ but redirect some of the requests to new ones. url: forward:/3rd legacy: path: /** - url: http://legacy.example.com + url: https://legacy.example.com In this example we are strangling the "legacy" app which is mapped to @@ -2051,7 +2051,7 @@ it via the Zuul proxy. If the serviceId of the ConfigServer is configs and the Sidecar is on port 5678, then it can be accessed at http://localhost:5678/configserver Non-jvm app can take advantage of the Config Server’s ability to return YAML -documents. For example, a call to http://sidecar.local.spring.io:5678/configserver/default-master.yml +documents. For example, a call to https://sidecar.local.spring.io:5678/configserver/default-master.yml might result in a YAML document like the following eureka: client: