使用域在Camel上创建路由

时间:2015-08-05 18:39:27

标签: java apache-camel esb

我正在运行Apache Camel的实例,以便将请求代理到另一台服务器(取决于URI)。 Camel正在运行的服务器响应很多不同的域(例如app1.server.com,app2.server.com)。

通过使用jetty和http4,我能够通过这样做来代理请求:

from("jetty://http://app.server.com:8080/app1?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

from("jetty://http://app.server.com:8080/app2?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

有没有办法根据域名创建路由?像这样:

from("jetty://http://app1.server.com:8080?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

from("jetty://http://app2.server.com:8080?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");

非常感谢。

1 个答案:

答案 0 :(得分:0)

您可以像这样创建基于内容的路由器(http://camel.apache.org/content-based-router.html

from("jetty://http://0.0.0.0:8080")
    .choice()
        .when(header("host").contains("app1.server.com"))
            .log("app1.server.com").to(...)
        .when(header("host").contains("app2.server.com"))
            .log("app2.server.com").to(...);