Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The onCompletion DSL allows you to add custom routes/processors when the original Exchange is complete. Camel spin off a copy of the Exchange and routes it in a separate thread, kinda like a WireTap. This allows the original thread to continue while the onCompletion route is running concurrently. We decided for this model as we did not want the onCompletion route to interfere with the original route.TODO:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionTest.java}

By default the onCompletion will be triggered when the Exchange is complete and regardless if the Exchange completed with success or with an failure (such as an Exception was thrown). You can limit the trigger to only occur onCompleteOnly or by onFauilureOnly as shown below:TODO:

Wiki Markup
{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/OnCompletionOnFailureOnlyTest.java}

Using onCompletion from Spring DSL

The onCompletion is defined like this with Spring DSL:TODO:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringOnCompletionTest.xml}

And the onCompleteOnly and onFailureOnly is defined as a boolean attribute on the <onCompletion> tag so the failure example would be:TODO:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringOnCompletionOnFailureOnlyTest.xml}

See Also

  • Unit of Work