From cdf575d006dc9d202f73a026055ee052a7ed2d7e Mon Sep 17 00:00:00 2001 From: buildmaster Date: Fri, 19 Jan 2018 00:54:58 +0000 Subject: [PATCH] Sync docs from master to gh-pages --- ...ing_cloud_commons_common_abstractions.html | 37 ++++++++++++++++-- multi/multi_spring-cloud-commons.html | 2 +- single/spring-cloud-commons.html | 39 ++++++++++++++++--- spring-cloud-commons.xml | 35 ++++++++++++++++- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/multi/multi__spring_cloud_commons_common_abstractions.html b/multi/multi__spring_cloud_commons_common_abstractions.html index 6ea1f82b..db7fc6b8 100644 --- a/multi/multi__spring_cloud_commons_common_abstractions.html +++ b/multi/multi__spring_cloud_commons_common_abstractions.html @@ -77,7 +77,36 @@ you would like to use for a given service.

[Note]Note

client in the above examples should be replaced with your Ribbon client’s -name.

2.4.2 Multiple RestTemplate objects

If you want a RestTemplate that is not load balanced, create a RestTemplate +name.

If you want to add one or more RetryListener to your retry you will need to +create a bean of type LoadBalancedRetryListenerFactory and return the RetryListener array +you would like to use for a given service.

@Configuration
+public class MyConfiguration {
+    @Bean
+    LoadBalancedRetryListenerFactory retryListenerFactory() {
+        return new LoadBalancedRetryListenerFactory() {
+            @Override
+            public RetryListener[] createRetryListeners(String service) {
+                return new RetryListener[]{new RetryListener() {
+                    @Override
+                    public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
+                        //TODO Do you business...
+                        return true;
+                    }
+
+                    @Override
+                     public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
+                        //TODO Do you business...
+                    }
+
+                    @Override
+                    public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
+                        //TODO Do you business...
+                    }
+                }};
+            }
+        };
+    }
+}

2.5 Multiple RestTemplate objects

If you want a RestTemplate that is not load balanced, create a RestTemplate bean and inject it as normal. To access the load balanced RestTemplate use the @LoadBalanced qualifier when you create your @Bean.

[Important]Important

Notice the @Primary annotation on the plain RestTemplate declaration in the example below, to disambiguate the unqualified @Autowired injection.

@Configuration
 public class MyConfiguration {
@@ -110,7 +139,7 @@ the @LoadBalanced qualifier when you create your public String doStuff() {
         return restTemplate.getForObject("http://example.com", String.class);
     }
-}
[Tip]Tip

If you see errors like java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89 try injecting RestOperations instead or setting spring.aop.proxyTargetClass=true.

2.5 Spring WebFlux WebClient as a Load Balancer Client

WebClient can be configured to use the LoadBalancerClient. A `LoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath.

public class MyClass {
+}
[Tip]Tip

If you see errors like java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89 try injecting RestOperations instead or setting spring.aop.proxyTargetClass=true.

2.6 Spring WebFlux WebClient as a Load Balancer Client

WebClient can be configured to use the LoadBalancerClient. A `LoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath.

public class MyClass {
     @Autowired
     private LoadBalancerExchangeFilterFunction lbFunction;
 
@@ -124,7 +153,7 @@ the @LoadBalanced qualifier when you create your class);
     }
 }

The URI needs to use a virtual host name (ie. service name, not a host name). -The LoadBalancerClient is used to create a full physical address.

2.6 Ignore Network Interfaces

Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".

application.yml.  +The LoadBalancerClient is used to create a full physical address.

2.7 Ignore Network Interfaces

Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".

application.yml. 

spring:
   cloud:
     inetutils:
@@ -143,7 +172,7 @@ The LoadBalancerClient is used to create a full phy
   cloud:
     inetutils:
       useOnlySiteLocalInterfaces: true

-

2.7 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) +

2.8 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) as well as OK HTTP clients (OkHttpClientFactory). The OkHttpClientFactory bean will only be created if the OK HTTP jar is on the classpath. In addition, Spring Cloud Commons provides beans for creating the connection managers used by both clients, ApacheHttpClientConnectionManagerFactory for the Apache diff --git a/multi/multi_spring-cloud-commons.html b/multi/multi_spring-cloud-commons.html index f092de53..a16ad376 100644 --- a/multi/multi_spring-cloud-commons.html +++ b/multi/multi_spring-cloud-commons.html @@ -1,3 +1,3 @@ - Cloud Native Applications

\ No newline at end of file + Cloud Native Applications \ No newline at end of file diff --git a/single/spring-cloud-commons.html b/single/spring-cloud-commons.html index c8d4b46e..40028341 100644 --- a/single/spring-cloud-commons.html +++ b/single/spring-cloud-commons.html @@ -1,6 +1,6 @@ - Cloud Native Applications

Cloud Native Applications


Cloud Native is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development. A related discipline is that of building 12-factor Apps in which development practices are aligned with delivery and operations goals, for instance by using declarative programming and management and monitoring. Spring Cloud facilitates these styles of development in a number of specific ways and the starting point is a set of features that all components in a distributed system either need or need easy access to when required.

Many of those features are covered by Spring Boot, which we build on in Spring Cloud. Some more are delivered by Spring Cloud as two libraries: Spring Cloud Context and Spring Cloud Commons. Spring Cloud Context provides utilities and special services for the ApplicationContext of a Spring Cloud application (bootstrap context, encryption, refresh scope and environment endpoints). Spring Cloud Commons is a set of abstractions and common classes used in different Spring Cloud implementations (eg. Spring Cloud Netflix vs. Spring Cloud Consul).

If you are getting an exception due to "Illegal key size" and you are using Sun’s JDK, you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. See the following links for more information:

Extract files into JDK/jre/lib/security folder (whichever version of JRE/JDK x64/x86 you are using).

[Note]Note

Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at github.

1. Spring Cloud Context: Application Context Services

Spring Boot has an opinionated view of how to build an application + Cloud Native Applications

Cloud Native Applications


Cloud Native is a style of application development that encourages easy adoption of best practices in the areas of continuous delivery and value-driven development. A related discipline is that of building 12-factor Apps in which development practices are aligned with delivery and operations goals, for instance by using declarative programming and management and monitoring. Spring Cloud facilitates these styles of development in a number of specific ways and the starting point is a set of features that all components in a distributed system either need or need easy access to when required.

Many of those features are covered by Spring Boot, which we build on in Spring Cloud. Some more are delivered by Spring Cloud as two libraries: Spring Cloud Context and Spring Cloud Commons. Spring Cloud Context provides utilities and special services for the ApplicationContext of a Spring Cloud application (bootstrap context, encryption, refresh scope and environment endpoints). Spring Cloud Commons is a set of abstractions and common classes used in different Spring Cloud implementations (eg. Spring Cloud Netflix vs. Spring Cloud Consul).

If you are getting an exception due to "Illegal key size" and you are using Sun’s JDK, you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. See the following links for more information:

Extract files into JDK/jre/lib/security folder (whichever version of JRE/JDK x64/x86 you are using).

[Note]Note

Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at github.

1. Spring Cloud Context: Application Context Services

Spring Boot has an opinionated view of how to build an application with Spring: for instance it has conventional locations for common configuration file, and endpoints for common management and monitoring tasks. Spring Cloud builds on top of that and adds a few features that @@ -264,7 +264,36 @@ you would like to use for a given service.

[Note]Note

client in the above examples should be replaced with your Ribbon client’s -name.

2.4.2 Multiple RestTemplate objects

If you want a RestTemplate that is not load balanced, create a RestTemplate +name.

If you want to add one or more RetryListener to your retry you will need to +create a bean of type LoadBalancedRetryListenerFactory and return the RetryListener array +you would like to use for a given service.

@Configuration
+public class MyConfiguration {
+    @Bean
+    LoadBalancedRetryListenerFactory retryListenerFactory() {
+        return new LoadBalancedRetryListenerFactory() {
+            @Override
+            public RetryListener[] createRetryListeners(String service) {
+                return new RetryListener[]{new RetryListener() {
+                    @Override
+                    public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
+                        //TODO Do you business...
+                        return true;
+                    }
+
+                    @Override
+                     public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
+                        //TODO Do you business...
+                    }
+
+                    @Override
+                    public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
+                        //TODO Do you business...
+                    }
+                }};
+            }
+        };
+    }
+}

2.5 Multiple RestTemplate objects

If you want a RestTemplate that is not load balanced, create a RestTemplate bean and inject it as normal. To access the load balanced RestTemplate use the @LoadBalanced qualifier when you create your @Bean.

[Important]Important

Notice the @Primary annotation on the plain RestTemplate declaration in the example below, to disambiguate the unqualified @Autowired injection.

@Configuration
 public class MyConfiguration {
@@ -297,7 +326,7 @@ the @LoadBalanced qualifier when you create your public String doStuff() {
         return restTemplate.getForObject("http://example.com", String.class);
     }
-}
[Tip]Tip

If you see errors like java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89 try injecting RestOperations instead or setting spring.aop.proxyTargetClass=true.

2.5 Spring WebFlux WebClient as a Load Balancer Client

WebClient can be configured to use the LoadBalancerClient. A `LoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath.

public class MyClass {
+}
[Tip]Tip

If you see errors like java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89 try injecting RestOperations instead or setting spring.aop.proxyTargetClass=true.

2.6 Spring WebFlux WebClient as a Load Balancer Client

WebClient can be configured to use the LoadBalancerClient. A `LoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath.

public class MyClass {
     @Autowired
     private LoadBalancerExchangeFilterFunction lbFunction;
 
@@ -311,7 +340,7 @@ the @LoadBalanced qualifier when you create your class);
     }
 }

The URI needs to use a virtual host name (ie. service name, not a host name). -The LoadBalancerClient is used to create a full physical address.

2.6 Ignore Network Interfaces

Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".

application.yml.  +The LoadBalancerClient is used to create a full physical address.

2.7 Ignore Network Interfaces

Sometimes it is useful to ignore certain named network interfaces so they can be excluded from Service Discovery registration (eg. running in a Docker container). A list of regular expressions can be set that will cause the desired network interfaces to be ignored. The following configuration will ignore the "docker0" interface and all interfaces that start with "veth".

application.yml. 

spring:
   cloud:
     inetutils:
@@ -330,7 +359,7 @@ The LoadBalancerClient is used to create a full phy
   cloud:
     inetutils:
       useOnlySiteLocalInterfaces: true

-

2.7 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) +

2.8 HTTP Client Factories

Spring Cloud Commons provides beans for creating both Apache HTTP clients (ApacheHttpClientFactory) as well as OK HTTP clients (OkHttpClientFactory). The OkHttpClientFactory bean will only be created if the OK HTTP jar is on the classpath. In addition, Spring Cloud Commons provides beans for creating the connection managers used by both clients, ApacheHttpClientConnectionManagerFactory for the Apache diff --git a/spring-cloud-commons.xml b/spring-cloud-commons.xml index 6ce99d0d..3e00f010 100644 --- a/spring-cloud-commons.xml +++ b/spring-cloud-commons.xml @@ -4,7 +4,7 @@ Cloud Native Applications -2018-01-18 +2018-01-19 @@ -456,6 +456,38 @@ public class MyConfiguration { client in the above examples should be replaced with your Ribbon client’s name. +If you want to add one or more RetryListener to your retry you will need to +create a bean of type LoadBalancedRetryListenerFactory and return the RetryListener array +you would like to use for a given service. +@Configuration +public class MyConfiguration { + @Bean + LoadBalancedRetryListenerFactory retryListenerFactory() { + return new LoadBalancedRetryListenerFactory() { + @Override + public RetryListener[] createRetryListeners(String service) { + return new RetryListener[]{new RetryListener() { + @Override + public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) { + //TODO Do you business... + return true; + } + + @Override + public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { + //TODO Do you business... + } + + @Override + public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) { + //TODO Do you business... + } + }}; + } + }; + } +} +

Multiple RestTemplate objects @@ -501,7 +533,6 @@ public class MyClass { If you see errors like java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89 try injecting RestOperations instead or setting spring.aop.proxyTargetClass=true.
-
Spring WebFlux WebClient as a Load Balancer Client WebClient can be configured to use the LoadBalancerClient. A `LoadBalancerExchangeFilterFunction is auto-configured if spring-webflux is on the classpath.