[英]Apache camel route a URI to another URI
Is it possible to route all of request to another server directly?是否可以将所有请求直接路由到另一台服务器? For example route all of this project specific rest endpoint localhost:8080/get-something to another project endpoint like this: someIp:8081/get-something2.
例如,将所有此项目特定的 rest 端点 localhost:8080/get-something 路由到另一个项目端点,如下所示:someIp:8081/get-something2。 something like this:
像这样的东西:
from("localhost:8080/get-something")
.to("someIp:8081/get-something2")
or this:或这个:
rest()
.path("/get-something")
.get()
.route()
.to("someIp:8081/get-something2")
I've tried too many ways but I cant!我尝试了太多方法,但我做不到!
I think you want to use a WireTap, just going by your description.我认为您想使用 WireTap,只需按照您的描述进行即可。
So you'll do something like所以你会做类似的事情
''' from("localhost:8080/get-something"). ''' from("localhost:8080/get-something"). wiretap(“direct:endpoint1”) // will receive exchange.
窃听(“direct:endpoint1”)//将接收交换。 wiretap(“direct:endpoint2”) // will receive exchange.to(ACTUAL_DESTINATION);
wiretap(“direct:endpoint2”) // 将收到 exchange.to(ACTUAL_DESTINATION); // will receive exchange …;
// 将收到交换 ...;
''' '''
Then然后
''' from(“direct:endpoint1”).to(MY_SERVER1); ''' from(“direct:endpoint1”).to(MY_SERVER1);
from(“direct:endpoint2”).to(MY_SERVER2);从(“直接:端点2”)。到(MY_SERVER2); '''
'''
Something to note though, is that these are completely separate messages (think a carbon copy) only if you specify a custom processor via the onPrepareRef property不过需要注意的是,只有当您通过 onPrepareRef 属性指定自定义处理器时,这些消息才是完全独立的消息(认为是抄送)
You could use a http based component (jetty or undertow) as consumer (from) with matchOnUriPrefix=true
option and then send it to an http component using bridgeEndpoint=true
option.您可以使用基于 http 的组件(jetty 或 undertow)作为具有
matchOnUriPrefix=true
选项的消费者(来自),然后使用bridgeEndpoint=true
选项将其发送到 http 组件。
Example:例子:
from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://google.com/?bridgeEndpoint=true");
That way any request sent to localhost:8080/ will be forwarded to google.com/这样,任何发送到 localhost:8080/ 的请求都将被转发到 google.com/
Try http://localhost:8080/ in your browser and you will get google web page.在浏览器中尝试 http://localhost:8080/ ,您将获得 google web 页面。
Try http://localhost:8080/search?q=camel in your browser and you will get response for "camel" search.在您的浏览器中尝试 http://localhost:8080/search?q=camel ,您将收到“骆驼”搜索的响应。
In your case you could do:在你的情况下,你可以这样做:
from("undertow:http://localhost:8080/?matchOnUriPrefix=true")
.to("http4://localhost:8081/?bridgeEndpoint=true");
Docs:文件:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.