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);});
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/"}}
Application.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文件配置中,如果是,我们如何添加它。
感谢您的帮助。
由于
答案 0 :(得分:1)
根据骆驼文档The Load Balancer Pattern allows you to delegate to one of a number of endpoints using a variety of different load balancing policies
camel-urlrewrite 组件将允许您插入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
等。
相关的Camel Doc @ http://camel.apache.org/load-balancer.html