是否可以将所有请求直接路由到另一台服务器?例如,将所有此项目特定的休息端点 localhost:8080/get-something 路由到另一个项目端点,如下所示: someIp:8081/get-something2 。像这样:
from("localhost:8080/get-something")
.to("someIp:8081/get-something2")
或者这个:
rest()
.path("/get-something")
.get()
.route()
.to("someIp:8081/get-something2")
我尝试了太多方法,但我做不到!
答案 0 :(得分:0)
我认为您想使用 WireTap,只需按照您的描述进行即可。
所以你会做类似的事情
''' from("localhost:8080/get-something") .窃听(“直接:端点1”)//将接收交换 .窃听(“direct:endpoint2”)//将接收交换 .to(ACTUAL_DESTINATION); // 将收到交换 … ;
'''
然后
''' 从(“直接:端点1”) .to(MY_SERVER1);
from(“direct:endpoint2”) .to(MY_SERVER2); '''
需要注意的是,这些是完全独立的消息(想想抄本)仅当您通过 onPrepareRef 属性指定自定义处理器时
答案 1 :(得分:0)
您可以使用基于 http 的组件(jetty 或 undertow)作为消费者(来自)并使用 matchOnUriPrefix=true
选项,然后使用 bridgeEndpoint=true
选项将其发送到 http 组件。
示例:
from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://google.com/?bridgeEndpoint=true");
这样任何发送到 localhost:8080/ 的请求都会被转发到 google.com/
在浏览器中尝试 http://localhost:8080/,您将获得 google 网页。
在浏览器中尝试 http://localhost:8080/search?q=camel ,您将得到“camel”搜索的响应。
在你的情况下,你可以这样做:
from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://localhost:8081/?bridgeEndpoint=true");
文档: