Sync docs from master to gh-pages
This commit is contained in:
@@ -735,7 +735,7 @@ See <a href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/sp
|
||||
<div class="sect2">
|
||||
<h3 id="_spring_webclient_as_a_load_balancer_client"><a class="link" href="#_spring_webclient_as_a_load_balancer_client">Spring WebClient as a Load Balancer Client</a></h3>
|
||||
<div class="paragraph">
|
||||
<p><code>WebClient</code> can be automatically configured to use the <code>LoadBalancerClient</code>.
|
||||
<p><code>WebClient</code> can be automatically configured to use a load-balancer client.
|
||||
To create a load-balanced <code>WebClient</code>, create a <code>WebClient.Builder</code> <code>@Bean</code> and use the <code>@LoadBalanced</code> qualifier, as shown in the following example:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
@@ -765,6 +765,40 @@ public class MyClass {
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The Ribbon client is used to create a full physical address.</p>
|
||||
</div>
|
||||
<div class="admonitionblock important">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<i class="fa icon-important" title="Important"></i>
|
||||
</td>
|
||||
<td class="content">
|
||||
If you want to use a <code>@LoadBalanced WebClient.Builder</code>, you need to have a loadbalancer
|
||||
implementation in the classpath. It is recommended that you add the
|
||||
<code>org.springframework.cloud:spring-cloud-loadbalancer</code> dependency to your project.
|
||||
Then, <code>ReactiveLoadBalancer</code> will be used underneath.
|
||||
Alternatively, this functionality will also work with spring-cloud-starter-netflix-ribbon, but the request
|
||||
will be handled by a non-reactive <code>LoadBalancerClient</code> under the hood. Additionally,
|
||||
spring-cloud-starter-netflix-ribbon is already in maintenance mode, so we do not recommned
|
||||
adding it to new projects.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="admonitionblock tip">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<i class="fa icon-tip" title="Tip"></i>
|
||||
</td>
|
||||
<td class="content">
|
||||
The <code>ReactorLoadBalancer</code> used underneath supports caching. If <code>cacheManager</code> is detected,
|
||||
cached version of <code>ServiceInstanceSupplier</code> will be used. If not, we will retrieve instances
|
||||
from discovery service without caching them. We recommend <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html">enabling caching</a> in your project
|
||||
if you use <code>ReactiveLoadBalancer</code>.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_retrying_failed_requests"><a class="link" href="#_retrying_failed_requests">Retrying Failed Requests</a></h4>
|
||||
<div class="paragraph">
|
||||
@@ -915,8 +949,45 @@ If you see errors such as <code>java.lang.IllegalArgumentException: Can not set
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="loadbalanced-webclient"><a class="link" href="#loadbalanced-webclient">Spring WebFlux WebClient as a Load Balancer Client</a></h3>
|
||||
<div class="sect3">
|
||||
<h4 id="webflux-with-reactive-loadbalancer"><a class="link" href="#webflux-with-reactive-loadbalancer">Spring WebFlux WebClient with Reactive Load Balancer</a></h4>
|
||||
<div class="paragraph">
|
||||
<p><code>WebClient</code> can be configured to use the <code>LoadBalancerClient</code>. <code>LoadBalancerExchangeFilterFunction</code> is auto-configured if <code>spring-webflux</code> is on the classpath. The following example shows how to configure a <code>WebClient</code> to use load balancer:</p>
|
||||
<p><code>WebClient</code> can be configured to use the <code>ReactiveLoadBalancer</code>.
|
||||
If you add <code>org.springframework.cloud:spring-cloud-loadbalancer</code> to your project,
|
||||
<code>ReactorLoadBalancerExchangeFilterFunction</code> is auto-configured if <code>spring-webflux</code> is on the classpath.
|
||||
The following example shows how to configure a <code>WebClient</code> to use reactive load balancer under the hood:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class MyClass {
|
||||
@Autowired
|
||||
private ReactorLoadBalancerExchangeFilterFunction lbFunction;
|
||||
|
||||
public Mono<String> doOtherStuff() {
|
||||
return WebClient.builder().baseUrl("http://stores")
|
||||
.filter(lbFunction)
|
||||
.build()
|
||||
.get()
|
||||
.uri("/stores")
|
||||
.retrieve()
|
||||
.bodyToMono(String.class);
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The <code>ReactorLoadBalancerClient</code> is used to create a full physical address.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_spring_webflux_webclient_with_non_reactive_load_balancer_client"><a class="link" href="#_spring_webflux_webclient_with_non_reactive_load_balancer_client">Spring WebFlux WebClient with non-reactive Load Balancer Client</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>If you you don’t have <code>org.springframework.cloud:spring-cloud-loadbalancer</code> in your project,
|
||||
but you do have spring-cloud-starter-netflix-ribbon, you can still use <code>WebClient</code> with <code>LoadBalancerClient</code>. <code>LoadBalancerExchangeFilterFunction</code>
|
||||
will be auto-configured if <code>spring-webflux</code> is on the classpath. Please note, however, that this is
|
||||
uses a non-reactive client under the hood.
|
||||
The following example shows how to configure a <code>WebClient</code> to use load balancer:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -940,6 +1011,50 @@ If you see errors such as <code>java.lang.IllegalArgumentException: Can not set
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The <code>LoadBalancerClient</code> is used to create a full physical address.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>WARN:
|
||||
This approach is now deprecated.
|
||||
We suggest you use <a href="#webflux-with-reactive-loadbalancer">WebFlux with reactive Load-Balancer</a>
|
||||
instead.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_passing_your_own_load_balancer_client_configuration"><a class="link" href="#_passing_your_own_load_balancer_client_configuration">Passing your own Load-Balancer Client configuration</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>You can also use the <code>@LoadBalancerClient</code> annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Configuration
|
||||
@LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class)
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public WebClient.Builder loadBalancedWebClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>It is also possible to pass together multiple configurations (for more than one load-balancer client) via the <code>@LoadBalancerClients</code> annotation, as shown below:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Configuration
|
||||
@LoadBalancerClients({@LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class), @LoadBalancerClient(value = "customers", configuration = CustomersLoadBalancerClientConfiguration.class)})
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public WebClient.Builder loadBalancedWebClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="ignore-network-interfaces"><a class="link" href="#ignore-network-interfaces">Ignore Network Interfaces</a></h3>
|
||||
|
||||
@@ -735,7 +735,7 @@ See <a href="https://github.com/spring-cloud/spring-cloud-netflix/blob/master/sp
|
||||
<div class="sect2">
|
||||
<h3 id="_spring_webclient_as_a_load_balancer_client"><a class="link" href="#_spring_webclient_as_a_load_balancer_client">Spring WebClient as a Load Balancer Client</a></h3>
|
||||
<div class="paragraph">
|
||||
<p><code>WebClient</code> can be automatically configured to use the <code>LoadBalancerClient</code>.
|
||||
<p><code>WebClient</code> can be automatically configured to use a load-balancer client.
|
||||
To create a load-balanced <code>WebClient</code>, create a <code>WebClient.Builder</code> <code>@Bean</code> and use the <code>@LoadBalanced</code> qualifier, as shown in the following example:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
@@ -765,6 +765,40 @@ public class MyClass {
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The Ribbon client is used to create a full physical address.</p>
|
||||
</div>
|
||||
<div class="admonitionblock important">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<i class="fa icon-important" title="Important"></i>
|
||||
</td>
|
||||
<td class="content">
|
||||
If you want to use a <code>@LoadBalanced WebClient.Builder</code>, you need to have a loadbalancer
|
||||
implementation in the classpath. It is recommended that you add the
|
||||
<code>org.springframework.cloud:spring-cloud-loadbalancer</code> dependency to your project.
|
||||
Then, <code>ReactiveLoadBalancer</code> will be used underneath.
|
||||
Alternatively, this functionality will also work with spring-cloud-starter-netflix-ribbon, but the request
|
||||
will be handled by a non-reactive <code>LoadBalancerClient</code> under the hood. Additionally,
|
||||
spring-cloud-starter-netflix-ribbon is already in maintenance mode, so we do not recommned
|
||||
adding it to new projects.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="admonitionblock tip">
|
||||
<table>
|
||||
<tr>
|
||||
<td class="icon">
|
||||
<i class="fa icon-tip" title="Tip"></i>
|
||||
</td>
|
||||
<td class="content">
|
||||
The <code>ReactorLoadBalancer</code> used underneath supports caching. If <code>cacheManager</code> is detected,
|
||||
cached version of <code>ServiceInstanceSupplier</code> will be used. If not, we will retrieve instances
|
||||
from discovery service without caching them. We recommend <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html">enabling caching</a> in your project
|
||||
if you use <code>ReactiveLoadBalancer</code>.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_retrying_failed_requests"><a class="link" href="#_retrying_failed_requests">Retrying Failed Requests</a></h4>
|
||||
<div class="paragraph">
|
||||
@@ -915,8 +949,45 @@ If you see errors such as <code>java.lang.IllegalArgumentException: Can not set
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="loadbalanced-webclient"><a class="link" href="#loadbalanced-webclient">Spring WebFlux WebClient as a Load Balancer Client</a></h3>
|
||||
<div class="sect3">
|
||||
<h4 id="webflux-with-reactive-loadbalancer"><a class="link" href="#webflux-with-reactive-loadbalancer">Spring WebFlux WebClient with Reactive Load Balancer</a></h4>
|
||||
<div class="paragraph">
|
||||
<p><code>WebClient</code> can be configured to use the <code>LoadBalancerClient</code>. <code>LoadBalancerExchangeFilterFunction</code> is auto-configured if <code>spring-webflux</code> is on the classpath. The following example shows how to configure a <code>WebClient</code> to use load balancer:</p>
|
||||
<p><code>WebClient</code> can be configured to use the <code>ReactiveLoadBalancer</code>.
|
||||
If you add <code>org.springframework.cloud:spring-cloud-loadbalancer</code> to your project,
|
||||
<code>ReactorLoadBalancerExchangeFilterFunction</code> is auto-configured if <code>spring-webflux</code> is on the classpath.
|
||||
The following example shows how to configure a <code>WebClient</code> to use reactive load balancer under the hood:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class MyClass {
|
||||
@Autowired
|
||||
private ReactorLoadBalancerExchangeFilterFunction lbFunction;
|
||||
|
||||
public Mono<String> doOtherStuff() {
|
||||
return WebClient.builder().baseUrl("http://stores")
|
||||
.filter(lbFunction)
|
||||
.build()
|
||||
.get()
|
||||
.uri("/stores")
|
||||
.retrieve()
|
||||
.bodyToMono(String.class);
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The <code>ReactorLoadBalancerClient</code> is used to create a full physical address.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_spring_webflux_webclient_with_non_reactive_load_balancer_client"><a class="link" href="#_spring_webflux_webclient_with_non_reactive_load_balancer_client">Spring WebFlux WebClient with non-reactive Load Balancer Client</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>If you you don’t have <code>org.springframework.cloud:spring-cloud-loadbalancer</code> in your project,
|
||||
but you do have spring-cloud-starter-netflix-ribbon, you can still use <code>WebClient</code> with <code>LoadBalancerClient</code>. <code>LoadBalancerExchangeFilterFunction</code>
|
||||
will be auto-configured if <code>spring-webflux</code> is on the classpath. Please note, however, that this is
|
||||
uses a non-reactive client under the hood.
|
||||
The following example shows how to configure a <code>WebClient</code> to use load balancer:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
@@ -940,6 +1011,50 @@ If you see errors such as <code>java.lang.IllegalArgumentException: Can not set
|
||||
<p>The URI needs to use a virtual host name (that is, a service name, not a host name).
|
||||
The <code>LoadBalancerClient</code> is used to create a full physical address.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>WARN:
|
||||
This approach is now deprecated.
|
||||
We suggest you use <a href="#webflux-with-reactive-loadbalancer">WebFlux with reactive Load-Balancer</a>
|
||||
instead.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_passing_your_own_load_balancer_client_configuration"><a class="link" href="#_passing_your_own_load_balancer_client_configuration">Passing your own Load-Balancer Client configuration</a></h4>
|
||||
<div class="paragraph">
|
||||
<p>You can also use the <code>@LoadBalancerClient</code> annotation to pass your own load-balancer client configuration, passing the name of the load-balancer client and the configuration class, like so:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Configuration
|
||||
@LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class)
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public WebClient.Builder loadBalancedWebClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>It is also possible to pass together multiple configurations (for more than one load-balancer client) via the <code>@LoadBalancerClients</code> annotation, as shown below:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">@Configuration
|
||||
@LoadBalancerClients({@LoadBalancerClient(value = "stores", configuration = StoresLoadBalancerClientConfiguration.class), @LoadBalancerClient(value = "customers", configuration = CustomersLoadBalancerClientConfiguration.class)})
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public WebClient.Builder loadBalancedWebClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
}</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="ignore-network-interfaces"><a class="link" href="#ignore-network-interfaces">Ignore Network Interfaces</a></h3>
|
||||
|
||||
Reference in New Issue
Block a user