sar*_*_pc 12 java spring apache-camel
对每条路线使用end()是最佳做法吗?
以下作品:
from("jms:some-queue")
.beanRef("bean1", "method1")
.beanRef("bean2", "method2")
Run Code Online (Sandbox Code Playgroud)
这样,
from("jms:some-queue")
.beanRef("bean1", "method1")
.beanRef("bean2", "method2")
.end()
Run Code Online (Sandbox Code Playgroud)
Fri*_*rdt 15
没有!呼吁end()"结束"骆驼路线不是最佳做法,不会产生任何功能上的好处.
对于常见的ProcessorDefinition函数to(),bean()或者log()它只是导致对endParent()方法的调用,从Camel源代码可以看出,它做的很少:
public ProcessorDefinition<?> endParent() {
return this;
}
调用end()是必需的,一旦你调用了处理器定义来启动他们自己的块,并且最显着地包括TryDefinitionsaka doTry()和ChoiceDefinitionsaka choice(),但也知道像split(), loadBalance(), onCompletion()或的函数recipientList().
小智 6
如果要结束正在运行的特定路由,则必须使用end().在onCompletion的例子中可以得到最好的解释
from("direct:start")
.onCompletion()
// this route is only invoked when the original route is complete as a kind
// of completion callback
.to("log:sync")
.to("mock:sync")
// must use end to denote the end of the onCompletion route
.end()
// here the original route contiues
.process(new MyProcessor())
.to("mock:result");
Run Code Online (Sandbox Code Playgroud)
在这里你必须结束指示与onCompletion相关的操作已经完成,并且你正在原始的死记硬背上恢复操作.
如果您使用XML DSL而不是Java,这将变得更加清晰和易于理解.因为在此您不必使用结束标记.XML的结束标记将负责编写end().下面是用XML DSL编写的完全相同的示例
<route>
<from uri="direct:start"/>
<!-- this onCompletion block will only be executed when the exchange is done being routed -->
<!-- this callback is always triggered even if the exchange failed -->
<onCompletion>
<!-- so this is a kinda like an after completion callback -->
<to uri="log:sync"/>
<to uri="mock:sync"/>
</onCompletion>
<process ref="myProcessor"/>
<to uri="mock:result"/>
Run Code Online (Sandbox Code Playgroud)