Camel - using end ()

Is it better to use end () for each route?

The following works:

from("jms:some-queue")      
    .beanRef("bean1", "method1")
    .beanRef("bean2", "method2")

so,

from("jms:some-queue")      
    .beanRef("bean1", "method1")
    .beanRef("bean2", "method2")
    .end()
+4
source share
2 answers

No! Calling end()to “complete” a camel route is not a best practice and will not provide any functional benefits.

For ordinary ProcessorDefinition functions, such as to(), bean()or log(), this simply results in calling the endParent () method, which, as can be seen from the Camel source code, is very small:

public ProcessorDefinition<?> endParent() { return this; }

end(), , , TryDefinitions aka doTry() ChoiceDefinitions aka choice(), , split(), loadBalance(), onCompletion() recipientList().

+7

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");

, , , onCompletion, , rote.

, 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"/>

+4

Source: https://habr.com/ru/post/1616516/


All Articles