第 283 章 Ribbon 组件
作为 Camel 2.18 版提供
ribbon 组件提供对客户端侧负载平衡的 Netflix Ribbon 使用。
Maven 用户需要将以下依赖项添加到其 pom.xml
中:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-ribbon</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
当使用 ServiceCall EIP 时,这个组件有助于在客户端中应用负载平衡功能。
283.1. 配置
Programmatic
RibbonConfiguration configuration = new RibbonConfiguration(); configuration.addProperties("ServerListRefreshInterval", "250"); RibbonLoadBalancer loadBalancer = new RibbonLoadBalancer(configuration); from("direct:start") .serviceCall() .name("myService") .loadBalancer(loadBalancer) .consulServiceDiscovery() .end() .to("mock:result");
Spring Boot
application.properties
camel.cloud.ribbon.properties[ServerListRefreshInterval] = 250
Routes
from("direct:start") .serviceCall() .name("myService") .ribbonLoadBalancer() .consulServiceDiscovery() .end() .to("mock:result");
XML
<route> <from uri="direct:start"/> <serviceCall name="myService"> <!-- enable ribbon load balancer --> <ribbonLoadBalancer> <properties key="ServerListRefreshInterval" value="250"/> </ribbonLoadBalancer> </serviceCall> </route>