[英]Dynamic Router URI in Apache Camel
I'm following chapter 8 of "Camel in Action" book and testing with Dynamic router. 我正在学习《骆驼在行动》一书的第8章,并使用动态路由器进行测试。 I have defined two routes as below:
我定义了以下两条路线:
from("direct:start")
.dynamicRouter(method(DynamicRouterBean.class, "route"))
.log("dynamicRoute result = ${body}");
from("seda:a")
.log("In direct:a with message ${body}");
And in the DynamicRouterBean's route method, I have implemented route logic as follows: 在DynamicRouterBean的route方法中,我实现了如下的路由逻辑:
public String route(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
System.out.println("Enter DynamicRouterBean, body=" + body + ", previous=" + previous);
if (previous == null) {
return "seda://a";
} else if ("seda://a".equals(previous)) {
return "language://simple:Bye ${body}";
} else {
// no more, so return null to indicate end of dynamic router
return null;
}
}
The code works as the book described... but the issue I recognized is that if I return endpoint URI without double slash "//" in the middle in the route method, the second condition to check previous equals "seda:a" will fail and so the dynamic route will stop there 该代码就像本书所描述的那样工作...但是我认识到的问题是,如果我在route方法的中间返回端点URI且中间没有双斜杠“ //”,则检查前一个等于“ seda:a”的第二个条件将失败,因此动态路线将在那里停止
if (previous == null) {
return "seda:a";
} else if ("seda:a".equals(previous)) {
// This condition will not match... and it will return null
return "language:simple:Bye ${body}";
} else {
// no more, so return null to indicate end of dynamic router
return null;
}
Is it a feature that Camel's DynamicRouter require the addition of "//" in the middle of the URI? 骆驼的DynamicRouter是否需要在URI中间添加“ //”这一功能? I search around the book or the Camel official website but seem not mentioned about this... If yes, any reason behind this?
我在这本书或骆驼的官方网站上搜索,但似乎没有提及此事。如果是,这背后的原因是什么?
Yes endpoints in Camel are formatted as name://context-path?options
eg with those double slashes. 是的,Camel中的端点格式为
name://context-path?options
例如带有那些双斜杠。 So if you compare then to as in the book. 因此,如果您将其与书中的进行比较。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.