Camel - using end()

saravana_pc picture saravana_pc · Nov 19, 2015 · Viewed 10.5k times · Source

Is it a best practice to use end() for every route?

The following works:

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

and so is this,

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

Answer

Fritz Duchardt picture Fritz Duchardt · Nov 19, 2015

No! Calling end() to "end" a Camel route is not a best practice and won't yield any functional benefits.

For common ProcessorDefinition functions like to(), bean() or log() it simply leads to a call to the endParent() method, which as one can see from the Camel source code, does very little:

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

The call to end() is required, once you have called processor definitions that start their own block and most prominently includes TryDefinitions aka doTry() and ChoiceDefinitions aka choice(), but also well know functions like split(), loadBalance(), onCompletion() or recipientList().