@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start") .pollEnrich().simple("jpa://" + Customer.class.getName() + "?query=select c from Customer c where c.name like '${header.name}'") .aggregationStrategy((a, b) -> { String name = b.getIn().getBody(Customer.class).getName(); String phrase = a.getIn().getBody(String.class).replace("NAME", name); a.getIn().setBody(phrase); return a; }) .to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start") .pollEnrich().simple("jpa://" + Customer.class.getName() + "?query=select c from Customer c where c.name like '${header.name}'") .timeout(5000) .aggregationStrategy((a, b) -> { String name = b.getIn().getBody(Customer.class).getName(); String phrase = a.getIn().getBody(String.class).replace("NAME", name); a.getIn().setBody(phrase); return a; }) .to("mock:result"); } }; }
@Test public void testRollbackUsingXmlQueueToQueue() throws Exception { // configure routes and add to camel context context.addRoutes(new SpringRouteBuilder() { @Override public void configure() throws Exception { Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class); from("activemq:queue:foo?transacted=true").policy(required).process(new ConditionalExceptionProcessor()) .to("activemq:queue:bar?transacted=true"); } }); assertResult(); }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // use required as transaction policy SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class); // configure to use transaction error handler and pass on the required as it will fetch // the transaction manager from it that it needs errorHandler(transactionErrorHandler(required)); // on exception is also supported onException(IllegalArgumentException.class).handled(false).to("mock:error").rollback(); from("direct:okay") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 // on exception is also supported // so if an IllegalArgumentException is thrown then we route it to the mock:error // since we mark it as handled then the exchange will NOT rollback onException(IllegalArgumentException.class).handled(true).to("mock:error"); from("direct:okay") // mark this route as transacted .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") // mark this route as transacted .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { onException(IllegalArgumentException.class).maximumRedeliveries(3); // START SNIPPET: e1 from("direct:okay") // marks this route as transacted, and we dont pass in any parameters so we // will auto lookup and use the Policy defined in the spring XML file .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); // marks this route as transacted that will use the single policy defined in the registry from("direct:fail") // marks this route as transacted, and we dont pass in any parameters so we // will auto lookup and use the Policy defined in the spring XML file .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 // on exception is also supported // so if an IllegalArgumentException is thrown then we route it to the mock:error // since we have handled = false then the exception is not handled and Camel will // rollback onException(IllegalArgumentException.class).handled(false).to("mock:error"); from("direct:okay") // mark this route as transacted .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") // mark this route as transacted .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // ignore failure if its something with Donkey onException(IllegalArgumentException.class).onWhen(exceptionMessage().contains("Donkey")).handled(true); from("direct:okay") // mark this route as transacted .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); from("direct:fail") // and this route is not transacted .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { from("direct:required") .transacted("PROPATATION_REQUIRED") .bean("bookService"); from("direct:required2") .transacted("PROPATATION_REQUIRED") .bean("bookService") .bean("bookService"); from("direct:new") .transacted("PROPAGATION_REQUIRES_NEW") .bean("bookService"); from("direct:requiredAndNew").to("direct:required", "direct:new"); from("direct:requiredAndNewRollback") .to("direct:required") // change to donkey so it will rollback .setBody(constant("Donkey in Action")) .to("direct:new"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // use required as transaction policy SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class); // configure to use transaction error handler and pass on the required as it will fetch // the transaction manager from it that it needs errorHandler(transactionErrorHandler(required)); onException(IllegalArgumentException.class) .handled(true).to("mock:error").rollback(); from("direct:okay") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { from("file://target/transacted/okay") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("file://target/transacted/fail?moveFailed=../failed") .onException(IllegalArgumentException.class) .handled(false) .to("mock:error") .end() .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 // use a global transaction error handler so all routes is transacted errorHandler(transactionErrorHandler()); from("direct:okay") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); // marks this route as transacted that will use the single policy defined in the registry from("direct:fail") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { // Notice that we use the SpringRouteBuilder that has a few more features than // the standard RouteBuilder return new SpringRouteBuilder() { public void configure() throws Exception { // setup the transaction policy SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class); // use transaction error handler errorHandler(transactionErrorHandler(required)); // must setup policy for each route from("direct:okay").policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); // must setup policy for each route from("direct:fail").policy(required) .setBody(constant("Tiger in Action")).bean("bookService") // force a rollback .rollback(); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { onException(IllegalArgumentException.class) .handled(true).to("mock:error").transform(constant("Sorry")).markRollbackOnly(); from("direct:okay") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 from("direct:okay") // marks this route as transacted, and we dont pass in any parameters so we // will auto lookup and use the Policy defined in the spring XML file .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); // marks this route as transacted that will use the single policy defined in the registry from("direct:fail") // marks this route as transacted, and we dont pass in any parameters so we // will auto lookup and use the Policy defined in the spring XML file .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { from("direct:okay") // use local on exception .onException(IllegalArgumentException.class) .handled(false) .to("mock:error") .end() .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") // use local on exception .onException(IllegalArgumentException.class) .handled(false) .to("mock:error") .end() .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { interceptSendToEndpoint("direct:(foo|bar)").to("mock:intercepted"); from("direct:okay") .transacted() .to("direct:foo") .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .to("direct:bar") .setBody(constant("Donkey in Action")).bean("bookService"); from("direct:foo").to("log:okay"); from("direct:bar").to("mock:fail"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { onException(IllegalArgumentException.class).handled(false).to("mock:error"); from("file://target/transacted/okay") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("file://target/transacted/fail?moveFailed=../failed") .transacted() .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // use required as transaction policy SpringTransactionPolicy required = lookup("PROPAGATION_REQUIRED", SpringTransactionPolicy.class); // configure to use transaction error handler and pass on the required as it will fetch // the transaction manager from it that it needs errorHandler(transactionErrorHandler(required)); // on exception is also supported onException(IllegalArgumentException.class).handled(false).to("mock:error"); from("direct:okay") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService"); from("direct:fail") .policy(required) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 // set the required policy for this route to indicate its transactional from("direct:okay").policy("PROPAGATION_REQUIRED"). setBody(constant("Tiger in Action")).bean("bookService"). setBody(constant("Elephant in Action")).bean("bookService"); // set the required policy for this route to indicate its transactional from("direct:fail").policy("PROPAGATION_REQUIRED"). setBody(constant("Tiger in Action")).bean("bookService"). setBody(constant("Donkey in Action")).bean("bookService"); // END SNIPPET: e1 } }; }
protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { public void configure() throws Exception { // ignore failure if its something with Donkey onException(IllegalArgumentException.class).onWhen(exceptionMessage().contains("Donkey")).handled(true); from("direct:okay") // mark this route as transacted .errorHandler(transactionErrorHandler().maximumRedeliveries(3)) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Elephant in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); from("direct:fail") // and this route is not transacted .errorHandler(defaultErrorHandler()) .setBody(constant("Tiger in Action")).bean("bookService") .setBody(constant("Donkey in Action")).bean("bookService"); } }; }
@Override protected RouteBuilder createRouteBuilder() throws Exception { return new SpringRouteBuilder() { @Override public void configure() throws Exception { from("activemq:queue:a") .transacted() .to("direct:quote") .to("activemq:queue:b"); from("direct:quote") .choice() .when(body().contains("Camel")) .transform(constant("Camel rocks")) .when(body().contains("Donkey")) .throwException(new IllegalArgumentException("Donkeys not allowed")) .otherwise() .transform(body().prepend("Hello ")); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { Tracer tracer = new Tracer(); tracer.setDestinationUri("jpa://" + JpaTraceEventMessage.class.getName() + "?persistenceUnit=trace"); tracer.setUseJpa(true); getContext().addInterceptStrategy(tracer); from("direct:start").routeId("foo").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName() + "?usePersist=true").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:startNotshared").to("jpa://" + SendEmail.class.getName() + "?"); from("direct:startShared").to("jpa://" + SendEmail.class.getName() + "?sharedEntityManager=true&joinTransaction=false"); from("jpa://" + SendEmail.class.getName() + "?sharedEntityManager=true&joinTransaction=false").routeId("jpaShared").autoStartup(false).process(new LatchProcessor()).to("mock:result"); from("jpa://" + SendEmail.class.getName() + "?sharedEntityManager=false").routeId("jpaOwn").autoStartup(false).process(new LatchProcessor()).to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start") .id("foo") .to("jpa://" + SendEmail.class.getName() + "?usePassedInEntityManager=true") .to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName()).to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { @Override public void configure() { String options = "?consumer.skipLockedEntity=true"; //&consumer.lockModeType=PESSIMISTIC_FORCE_INCREMENT"; from("jpa://" + VersionedItem.class.getName() + options).routeId("first").autoStartup(false).bean(new WaitLatch()).log("route1: ${body}").to("mock:result1"); from("jpa2://select" + options + "&consumer.query=select s from VersionedItem s").routeId("second").autoStartup(false).bean(new WaitLatch()).log("route2: ${body}").to("mock:result2"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName()); from("jpa://" + SendEmail.class.getName() + "?consumeLockEntity=true").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName() + "?flushOnSend=true").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName()); from("jpa://" + SendEmail.class.getName()).to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName()); from("jpa://" + SendEmail.class.getName() + "?maxMessagesPerPoll=2&consumeDelete=false&delay=5000").to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start") .id("foo") .to("jpa://" + SendEmail.class.getName() + "?usePassedInEntityManager=true") .to("mock:result"); from("direct:remove") .id("foo1") .to("jpa://" + SendEmail.class.getName() + "?remove=true&usePassedInEntityManager=true") .to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() throws Exception { JpaEndpoint jpa = new JpaEndpoint(); jpa.setCamelContext(context); jpa.setEntityType(SendEmail.class); jpa.setEntityManagerFactory(context.getRegistry().lookupByNameAndType("entityManagerFactory", EntityManagerFactory.class)); from("direct:start").to(jpa).to("mock:result"); } }; }
@Override protected RouteBuilder createRouteBuilder() { return new SpringRouteBuilder() { public void configure() { from("direct:start").to("jpa://" + SendEmail.class.getName()); from("jpa://" + SendEmail.class.getName() + "?maximumResults=1&consumeDelete=false&delay=5000").to("mock:result"); } }; }
@Test public void testRollbackUsingXmlQueueToProcessor() throws Exception { // configure routes and add to camel context context.addRoutes(new SpringRouteBuilder() { @Override public void configure() throws Exception { Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class); from("activemq:queue:foo").policy(required).process(new ConditionalExceptionProcessor()); } }); assertResult(); }
@Test public void testRollbackUsingXmlQueueToQueueRequestReplyUsingDynamicMessageSelector() throws Exception { final ConditionalExceptionProcessor cp = new ConditionalExceptionProcessor(5); context.addRoutes(new SpringRouteBuilder() { @Override public void configure() throws Exception { Policy required = lookup("PROPAGATION_REQUIRED_POLICY", SpringTransactionPolicy.class); from("activemq:queue:foo").policy(required).process(cp).to("activemq-1:queue:bar?replyTo=queue:bar.reply"); from("activemq-1:queue:bar").process(new Processor() { public void process(Exchange e) { String request = e.getIn().getBody(String.class); Message out = e.getOut(); String selectorValue = e.getIn().getHeader("camelProvider", String.class); if (selectorValue != null) { out.setHeader("camelProvider", selectorValue); } out.setBody("Re: " + request); } }); } }); for (int i = 0; i < 5; ++i) { Object reply = template.requestBody("activemq:queue:foo", "blah" + i); assertTrue("Received unexpeced reply", reply.equals("Re: blah" + i)); assertTrue(cp.getErrorMessage(), cp.getErrorMessage() == null); } }