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