【问题标题】:Apache camel route a URI to another URIApache骆驼将URI路由到另一个URI
【发布时间】:2021-08-23 23:10:36
【问题描述】:

是否可以将所有请求直接路由到另一台服务器?例如,将所有这个项目特定的休息端点 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")

我尝试了太多方法,但我做不到!

【问题讨论】:

    标签: java spring-boot apache-camel restlet http4s


    【解决方案1】:

    我认为你想使用 WireTap,只是按照你的描述。

    所以你会做类似的事情

    ''' from("localhost:8080/get-something") . wiretap(“direct:endpoint1”) // 将接收交换 .窃听(“direct:endpoint2”)//将接收交换 .to(ACTUAL_DESTINATION); // 将收到交换 … ;

    '''

    然后

    ''' 从(“直接:端点1”) .to(MY_SERVER1);

    from(“direct:endpoint2”) .to(MY_SERVER2); '''

    需要注意的是,这些是完全独立的消息(想想抄送)仅当您通过 onPrepareRef 属性指定自定义处理器时

    【讨论】:

    • 您的答案应该是可读的。请在写下答案时使用正确的选项。
    【解决方案2】:

    您可以使用matchOnUriPrefix=true 选项将基于http 的组件(jetty 或undertow)用作消费者(来自),然后使用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");
    

    文档:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      • 2014-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多