第 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. Configuration
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>