DatabaseRoutes.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.redhat.training.camel.database;
  2. import org.apache.camel.builder.RouteBuilder;
  3. import org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
  4. import org.springframework.stereotype.Component;
  5. import com.redhat.training.camel.database.RandomBean.RandomException;
  6. @Component
  7. public class DatabaseRoutes extends RouteBuilder {
  8. @Override
  9. public void configure() throws Exception {
  10. from("timer:singleRead?repeatCount=1")
  11. .routeId("jdbc-component")
  12. .setHeader("stuffid", constant(1))
  13. .setBody().simple("SELECT * FROM randomstuff WHERE id = ${header.stuffid}")
  14. .to("jdbc:mydb")
  15. .to("log:jdbcComponent?showAll=true");
  16. from("sql:SELECT * FROM randomstuff?dataSource=#mydb&repeatCount=1")
  17. .routeId("sql-component-no-params")
  18. .to("log:sqlComponentNoParam?showAll=true");
  19. from("timer:singleRead?repeatCount=1")
  20. .routeId("sql-component-with-param")
  21. .setHeader("stuffid", constant(3))
  22. .to("sql:SELECT * FROM randomstuff WHERE id = :#stuffid?dataSource=#mydb&repeatCount=1")
  23. .to("log:sqlComponentParam?showAll=true");
  24. from("jpa:com.redhat.training.camel.database.Item?persistenceUnit=jpaRoute&consumeDelete=false")
  25. .idempotentConsumer(simple("${body.id}"),
  26. MemoryIdempotentRepository.memoryIdempotentRepository(1000))
  27. .routeId("jpa-component-consumer")
  28. .to("log:jpaComponentConsumer?showAll=true");
  29. onException(RandomException.class)
  30. .to("log:randomExceptionHandler?showAll=true")
  31. .handled(true)
  32. .markRollbackOnly();
  33. from("timer:jpaStore?repeatCount=1")
  34. .routeId("jpa-component-producer")
  35. .transacted("myRequiresNewPolicy")
  36. .setBody().constant(new Item("ladder"))
  37. .to("log:jpaComponentProducerPre?showAll=true")
  38. .to("jpa:com.redhat.training.database.Item?persistenceUnit=jpaRoute")
  39. .to("log:jpaComponentProducerPost?showAll=true")
  40. .bean(RandomBean.class)
  41. .to("log:jpaAfterBean?showAll=true");
  42. }
  43. }