apache-camel - 如何在 apache camel 中为 http4 组件添加负载平衡。对于下面的 http4 组件代码检查
问题描述
对于下面的 http4 组件代码检查。
rules.getRules().forEach(x->{
from("jetty:http://0.0.0.0:"+rules.getPort()+"/"+x.getFrom()+"??matchOnUriPrefix=true")
.to("http4://"+x.getTo()+"?bridgeEndpoint=true&throwExceptionOnFailure=false");
System.out.println(“Ieration Route: ”+x);});
请检查下面的示例路由(X 值)
Ieration Route: {"RouteRule":{ "from":"posts", "to":"jsonplaceholder.typicode.com/posts/?"}}
Ieration Route: {"RouteRule":{ "from":"users", "to":"reqres.in/api/users"}}
Ieration Route: {"RouteRule":{ "from":"countries", "to":"restcountries.eu/rest/v2/"}}
应用程序.yml 文件
routes:
port: 8088
route:
-
from: posts
to: jsonplaceholder.typicode.com/posts/?
-
from: users
to: reqres.in/api/users
-
from: countries
to: restcountries.eu/rest/v2/
在上述场景中我们可以在哪里添加多个服务器?在 yml 文件配置中,如果是,我们如何添加它。
感谢您的帮助。
谢谢
解决方案
根据骆驼文档骆驼urlrewriteThe Load Balancer Pattern allows you to delegate to one of a number of endpoints using a variety of different load balancing policies
组件
将允许您插入url重写机制。
此故障转移负载平衡器可以按以下方式配置:
from("jetty:http://{host}:{{port}}/{context_1}?matchOnUriPrefix=true")
.loadBalance().failover(Exception.class)
.to("jetty:http://{host}:{{port2}}/context_2?bridgeEndpoint=true&urlRewrite=#myRewrite")
.to("jetty:http://{host}:{{port2}}/{other_context}?bridgeEndpoint=true&urlRewrite=#myRewrite");
*此组件要求您的 Camel 路由从基于 servlet 的端点开始,例如Jetty
您的代码已经拥有的端点。
相关骆驼文档@http ://camel.apache.org/load-balancer.html
推荐阅读
- java - 如何使用 Firebase ML Kit 文本识别检测图像中的小数
- python - TensorFlow 动态填充
- firebase - 文本小部件将实时 Fireabase 值检测为空
- python - Tkinter Button 通过单击鼠标具有打开和关闭功能
- python - kivy冻结屏幕
- twitter-oauth - Twitter oauth_signature 需要 urlencode(百分比十六进制编码)在签名库中的回调 url 上运行两次
- javascript - 脚本中未处理的 Promise Rejection
- java - 将 SQL 查询转换为 HQL、Java Hibernate 时出错
- php - 降低圈复杂度的设计模式
- sql - 在 Azure SQL 数据库中将 JSON 列数据转换为表格格式