@ -44,7 +44,7 @@ The properties you can use are <code class="literal">client.ribbon.MaxAutoRetrie
@@ -44,7 +44,7 @@ The properties you can use are <code class="literal">client.ribbon.MaxAutoRetrie
<codeclass="literal">client.ribbon.MaxAutoRetriesNextServer</code>, and <codeclass="literal">client.ribbon.OkToRetryOnAllOperations</code>.
See the <aclass="link"href="https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties"target="_top">Ribbon documentation</a>
for a description of what there properties do.</p><divclass="note"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Note"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Note]"src="images/note.png"></td><thalign="left">Note</th></tr><tr><tdalign="left"valign="top"><p><codeclass="literal">client</code> in the above examples should be replaced with your Ribbon client’s
name.</p></td></tr></table></div></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="_multiple_resttemplate_objects"href="#_multiple_resttemplate_objects"></a>2.4 Multiple RestTemplate objects</h2></div></div></div><p>If you want a <codeclass="literal">RestTemplate</code> that is not load balanced, create a <codeclass="literal">RestTemplate</code>
name.</p></td></tr></table></div></div><divclass="section"><divclass="titlepage"><div><div><h3class="title"><aname="_multiple_resttemplate_objects"href="#_multiple_resttemplate_objects"></a>2.3.2 Multiple RestTemplate objects</h3></div></div></div><p>If you want a <codeclass="literal">RestTemplate</code> that is not load balanced, create a <codeclass="literal">RestTemplate</code>
bean and inject it as normal. To access the load balanced <codeclass="literal">RestTemplate</code> use
the <codeclass="literal">@LoadBalanced</code> qualifier when you create your <codeclass="literal">@Bean</code>.</p><divclass="important"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Important"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Important]"src="images/important.png"></td><thalign="left">Important</th></tr><tr><tdalign="left"valign="top"><p>Notice the <codeclass="literal">@Primary</code> annotation on the plain <codeclass="literal">RestTemplate</code> declaration in the example below, to disambiguate the unqualified <codeclass="literal">@Autowired</code> injection.</p></td></tr></table></div><preclass="programlisting"><em><spanclass="hl-annotation"style="color: gray">@Configuration</span></em>
@ -77,7 +77,21 @@ the <code class="literal">@LoadBalanced</code> qualifier when you create your <c
@@ -77,7 +77,21 @@ the <code class="literal">@LoadBalanced</code> qualifier when you create your <c
}</pre><divclass="tip"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Tip"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Tip]"src="images/tip.png"></td><thalign="left">Tip</th></tr><tr><tdalign="left"valign="top"><p>If you see errors like <codeclass="literal">java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89</code> try injecting <codeclass="literal">RestOperations</code> instead or setting <codeclass="literal">spring.aop.proxyTargetClass=true</code>.</p></td></tr></table></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="ignore-network-interfaces"href="#ignore-network-interfaces"></a>2.5 Ignore Network Interfaces</h2></div></div></div><p>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".</p><p><b>application.yml. </b>
}</pre><divclass="tip"style="margin-left: 0.5in; margin-right: 0.5in;"><tableborder="0"summary="Tip"><tr><tdrowspan="2"align="center"valign="top"width="25"><imgalt="[Tip]"src="images/tip.png"></td><thalign="left">Tip</th></tr><tr><tdalign="left"valign="top"><p>If you see errors like <codeclass="literal">java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89</code> try injecting <codeclass="literal">RestOperations</code> instead or setting <codeclass="literal">spring.aop.proxyTargetClass=true</code>.</p></td></tr></table></div></div></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="loadbalanced-webclient"href="#loadbalanced-webclient"></a>2.4 Spring WebFlux WebClient as a Load Balancer Client</h2></div></div></div><p><codeclass="literal">WebClient</code> can be configured to use the <codeclass="literal">LoadBalancerClient. A `LoadBalancerExchangeFilterFunction</code> is auto-configured if spring-webflux is on the classpath.</p><preclass="programlisting"><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">public</span><spanxmlns:d="http://docbook.org/ns/docbook"class="hl-keyword">class</span> MyClass {
}</pre><p>The URI needs to use a virtual host name (ie. service name, not a host name).
The <codeclass="literal">LoadBalancerClient</code> is used to create a full physical address.</p></div><divclass="section"><divclass="titlepage"><div><div><h2class="title"style="clear: both"><aname="ignore-network-interfaces"href="#ignore-network-interfaces"></a>2.5 Ignore Network Interfaces</h2></div></div></div><p>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".</p><p><b>application.yml. </b>
@ -413,7 +413,6 @@ for a description of what there properties do.</simpara>
@@ -413,7 +413,6 @@ for a description of what there properties do.</simpara>
name.</simpara>
</note>
</section>
</section>
<sectionxml:id="_multiple_resttemplate_objects">
<title>Multiple RestTemplate objects</title>
<simpara>If you want a <literal>RestTemplate</literal> that is not load balanced, create a <literal>RestTemplate</literal>
@ -458,6 +457,27 @@ public class MyClass {
@@ -458,6 +457,27 @@ public class MyClass {
<simpara>If you see errors like <literal>java.lang.IllegalArgumentException: Can not set org.springframework.web.client.RestTemplate field com.my.app.Foo.restTemplate to com.sun.proxy.$Proxy89</literal> try injecting <literal>RestOperations</literal> instead or setting <literal>spring.aop.proxyTargetClass=true</literal>.</simpara>
</tip>
</section>
</section>
<sectionxml:id="loadbalanced-webclient">
<title>Spring WebFlux WebClient as a Load Balancer Client</title>
<simpara><literal>WebClient</literal> can be configured to use the <literal>LoadBalancerClient. A `LoadBalancerExchangeFilterFunction</literal> is auto-configured if spring-webflux is on the classpath.</simpara>
<programlistinglanguage="java"linenumbering="unnumbered">public class MyClass {
<simpara>The URI needs to use a virtual host name (ie. service name, not a host name).
The <literal>LoadBalancerClient</literal> is used to create a full physical address.</simpara>
</section>
<sectionxml:id="ignore-network-interfaces">
<title>Ignore Network Interfaces</title>
<simpara>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".</simpara>