четверг, 1 апреля 2010 г.

[DSL]: ApacheCamel

As i wrote early i like some 'specific' style of programming. So now i have yet some examples:

From here:
-------------------------
onException(ValidationException.class).to("activemq:validationFailed");

onException(MyFunctionalException.class).process(new MyFunctionFailureHandler()).stop();

from("jms:queue:order:input")
.to("bean:validateOrder");
.to("bean:transformOrder")
.to("bean:handleOrder");

from("direct:start")
.choice()
.when().xpath("//type = 'myType'").to("bean:myServiceBean")
.end()
.to("mock:result");

onException(MyUserException.class).onWhen(header("user").isNotNull())
.maximumRedeliveries(1)
.to(ERROR_USER_QUEUE);

from here:
-------------------------
from("direct:start")
.doTry()
.process(new ProcessorFail())
.to("mock:result")
.doCatch(IOException.class, IllegalStateException.class)
.to("mock:catch")
.doFinally()
.to("mock:finally")
.end();

from here:
-------------------------
from("jms:queue:order")
.choice()
.when(header("type").isEqualTo("widget")).to("bean:widgetOrder")
.when(header("type").isEqualTo("wombat")).to("bean:wombatOrder")
.otherwise()
.to("bean:miscOrder");

from("direct:start")
.choice()
.when(not(header("username").regex("goofy|pluto"))).to("mock:people")
.otherwise().to("mock:animals");
.end();

.end();

from here:
----------------------
from("direct:mixed2")
// using a different propagation which is requires new
.transacted("PROPAGATION_REQUIRES_NEW")
// tell Camel that if this route fails then only rollback this last route
// by using (rollback only *last*)
.onException(Exception.class).markRollbackOnlyLast().end()
// this step will be okay
.setBody(constant("Giraffe in Action")).beanRef("bookService")
// this step will fail with donkey
.setBody(constant("Donkey in Action")).beanRef("bookService");

Комментариев нет:

Отправить комментарий