Apache Camel Taking Camel for a ride Hands on Xke Alexis Kinsella June 11, 2010
www.xebia.fr / blog.xebia.fr What is camel ?
What is camel ? www.xebia.fr / blog.xebia.fr <ul><li>It stands for : </li></ul><ul><ul><li>C oncise  A pplication  M essag...
What is camel ? <ul><li>A powerful Spring based Integration Framework </li></ul><ul><li>It implements Enterprise Integrati...
What is camel ? <ul><li>Apache Camel uses URIs </li></ul><ul><ul><li>Works with any kind of transport or messaging such as...
www.xebia.fr / blog.xebia.fr Some informations before you start ...
About the authors (Camel Riders) <ul><li>James Strachan </li></ul><ul><ul><li>Technical director at FuseSource </li></ul><...
About the authors (Camel Riders) <ul><li>Jon Anstey </li></ul><ul><ul><li>Senior Engineer at Progress Software </li></ul><...
Camel and friends <ul><li>ActiveMQ </li></ul><ul><ul><li>Open source messaging provider (JMS provider). </li></ul></ul><ul...
Professionnal Camel Support <ul><li>FuseSource – Open Source SOA </li></ul><ul><ul><li>Get supported and fixed versions fo...
Competitors and Families of products <ul><li>ESB (Entreprise Service Bus): </li></ul><ul><ul><li>ServiceMix (JBI compliant...
Camel compared to Mule ... <ul><li>Both based on Spring + POJO </li></ul><ul><li>They can run in standalone mode or embedd...
Camel compared to Mule ... <ul><li>You don't need to create a lot of XML config files with inbound/outbound stuff like you...
www.xebia.fr / blog.xebia.fr The basics
Message Routing www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna...
Camel Components www.xebia.fr / blog.xebia.fr
Kick Ass features <ul><li>Integrates with almost everything … </li></ul><ul><li>Support for: </li></ul><ul><ul><li>Scripti...
Simple Routing www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna ...
Pipeline www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, ...
Multicast www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna,...
Message filter: Spring XML www.xebia.fr / blog.xebia.fr <? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&quot; ?>...
Message filter: Java DSL www.xebia.fr / blog.xebia.fr package  com.acme.quotes; import  org.apache.camel.builder.RouteBuil...
Content Based Router: Java www.xebia.fr / blog.xebia.fr from( &quot;activemq:NewOrders&quot; ). choice().when().xpath( &qu...
Content Based Router: Spring XML www.xebia.fr / blog.xebia.fr <? xml  version = &quot;1.0&quot;  encoding = &quot;UTF-8&qu...
How camel do this routing work ? <ul><li>Camel Components </li></ul><ul><ul><li>Camel Endpoints </li></ul></ul><ul><ul><ul...
Message processors www.xebia.fr / blog.xebia.fr from( &quot;direct:start&quot; ).process( new  Processor() { public   void...
Expressions www.xebia.fr / blog.xebia.fr <ul><li>Camel supports pluggable Expression strategies using a variety of differe...
Predicates www.xebia.fr / blog.xebia.fr <ul><li>Camel supports a pluggable interface called Predicate </li></ul><ul><ul><l...
Predicates examples www.xebia.fr / blog.xebia.fr from( &quot;jms:queue:order&quot; ) .choice() .when(header( &quot;type&qu...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Transaction Manager </li></ul><ul><li>< bean   id = &q...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Java DSL (1) </li></ul><ul><li>publi...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Java DSL (2) </li></ul><ul><li>from(...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Spring XML (1) </li></ul><ul><li><!-...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Spring XML (2) </li></ul><ul><li><!-...
Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>TransactionErrorHandler </li></ul><ul><li>onException ...
DefaultErrorHandler & DeadLetterChannel www.xebia.fr / blog.xebia.fr <ul><li>Client notified (Default DLC behavior, not DE...
Annotation support www.xebia.fr / blog.xebia.fr <ul><li>Camel supports annotations </li></ul><ul><li>public   class  Route...
@Bean annotation www.xebia.fr / blog.xebia.fr public   class  Foo { @ MessageDriven ( uri  =  &quot;activemq:my.queue&quot...
Groovy support www.xebia.fr / blog.xebia.fr <ul><li>Using Java DSL </li></ul><ul><li>// lets route if a line item is over ...
Testing with camel www.xebia.fr / blog.xebia.fr <ul><li>Testing of distributed and asynchronous processing is notoriously ...
Testing with camel www.xebia.fr / blog.xebia.fr public   class  FilterTest  extends  CamelTestSupport { @EndpointInject (u...
Spring Test with Java Config www.xebia.fr / blog.xebia.fr @ ContextConfiguration (  locations  =  &quot;org.apache.camel.s...
Camel riding from Java <ul><li>/META-INF/spring/camelContext.xml </li></ul><ul><li>Set the CLASSPATH </li></ul><ul><li>Run...
Camel & Maven <ul><li>mvn camel:run, camel:dot </li></ul><ul><li>Maven declaration:  </li></ul>www.xebia.fr / blog.xebia.f...
Maven site report <ul><li>Result of report plugin (Dot & GraphViz) </li></ul>www.xebia.fr / blog.xebia.fr
Where would I use Camel ? <ul><li>Standalone or in any Spring application </li></ul><ul><li>Inside ActiveMQ’s JMS client o...
www.xebia.fr / blog.xebia.fr Going further with Apache Camel …
Books <ul><li>Theme:  </li></ul><ul><ul><li>This book is essentially the Camel bible </li></ul></ul><ul><li>Edition:  </li...
Books <ul><li>Theme:  </li></ul><ul><ul><li>catalog of sixty-five patterns, with real-world solutions </li></ul></ul><ul><...
www.xebia.fr / blog.xebia.fr Twitter: @alexiskinsella Thank You
Upcoming SlideShare
Loading in...5
×

Xke - Introduction to Apache Camel

3,577

Published on

Introduction to Apache Camel

Published in: Technology, Design
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,577
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
122
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • 06/10/10
  • Xke - Introduction to Apache Camel

    1. 1. Apache Camel Taking Camel for a ride Hands on Xke Alexis Kinsella June 11, 2010
    2. 2. www.xebia.fr / blog.xebia.fr What is camel ?
    3. 3. What is camel ? www.xebia.fr / blog.xebia.fr <ul><li>It stands for : </li></ul><ul><ul><li>C oncise A pplication M essage E xchange L anguage (i.e. the Java DSL for routing) </li></ul></ul><ul><ul><li>Its is a routing and mediation framework </li></ul></ul><ul><li>Some people say that : </li></ul><ul><ul><li>A camel is a horse designed by committee (Not in that case ...) </li></ul></ul>
    4. 4. What is camel ? <ul><li>A powerful Spring based Integration Framework </li></ul><ul><li>It implements Enterprise Integration Patterns </li></ul><ul><li>Routing and mediation rules configured using : </li></ul><ul><ul><li>Java DSL (or Fluent API) </li></ul></ul><ul><ul><li>Spring Xml Configuration files. </li></ul></ul>www.xebia.fr / blog.xebia.fr
    5. 5. What is camel ? <ul><li>Apache Camel uses URIs </li></ul><ul><ul><li>Works with any kind of transport or messaging such as: </li></ul></ul><ul><ul><ul><li>HTTP, ActiveMQ, JMS, MINA or CXF Bus API, … </li></ul></ul></ul><ul><ul><ul><li>Working with pluggable Data Format options </li></ul></ul></ul><ul><ul><li>Works with the same API regardless which kind of Transport used. </li></ul></ul><ul><li>A Java library with minimal dependencies: </li></ul><ul><ul><li>easy embedding in any Java application. </li></ul></ul>www.xebia.fr / blog.xebia.fr
    6. 6. www.xebia.fr / blog.xebia.fr Some informations before you start ...
    7. 7. About the authors (Camel Riders) <ul><li>James Strachan </li></ul><ul><ul><li>Technical director at FuseSource </li></ul></ul><ul><ul><li>Blog: http://macstrac.blogspot.com/ </li></ul></ul><ul><ul><li>Co-founder: Scalate , ActiveMQ , Camel , ServiceMix , Lingo , Jencks , Groovy , dom4j </li></ul></ul><ul><ul><li>Committer: jaxen , taglibs , commons </li></ul></ul><ul><li>Claus Ibsen </li></ul><ul><ul><li>Software Engineer employed by Progress Software working in The FUSE team </li></ul></ul><ul><ul><li>Blog: http://davsclaus.blogspot.com/ </li></ul></ul><ul><ul><li>Leader: Camel </li></ul></ul>www.xebia.fr / blog.xebia.fr
    8. 8. About the authors (Camel Riders) <ul><li>Jon Anstey </li></ul><ul><ul><li>Senior Engineer at Progress Software </li></ul></ul><ul><ul><li>Blog: http://janstey.blogspot.com/ </li></ul></ul><ul><ul><li>Committer: ActiveMQ , Camel , ServiceMix </li></ul></ul><ul><li>Hiram Chirino </li></ul><ul><ul><li>A Software Architect at FuseSource </li></ul></ul><ul><ul><li>Blog: http://hiramchirino.com/blog/ </li></ul></ul><ul><ul><li>Co-founder: ActiveMQ , Camel </li></ul></ul><ul><ul><li>Committer: ServiceMix , Geronimo </li></ul></ul>www.xebia.fr / blog.xebia.fr
    9. 9. Camel and friends <ul><li>ActiveMQ </li></ul><ul><ul><li>Open source messaging provider (JMS provider). </li></ul></ul><ul><ul><li>Web site: http://activemq.apache.org </li></ul></ul><ul><ul><li>Current version: 5.3.2 </li></ul></ul><ul><li>CXF </li></ul><ul><ul><li>Open Source Service Framework (WebServices) </li></ul></ul><ul><ul><li>Web site: http://cxf.apache.org </li></ul></ul><ul><ul><li>Current version: 2.2.9 </li></ul></ul><ul><li>ServiceMix </li></ul><ul><ul><li>Open source ESB (Enterprise Service Bus) </li></ul></ul><ul><ul><li>Web site: http://servicemix.apache.org </li></ul></ul><ul><ul><li>Current versions: 3.3.2 / 4.2.0 (OSGI Based) </li></ul></ul><ul><li>Apache Mina ... </li></ul>www.xebia.fr / blog.xebia.fr
    10. 10. Professionnal Camel Support <ul><li>FuseSource – Open Source SOA </li></ul><ul><ul><li>Get supported and fixed versions for: </li></ul></ul><ul><ul><ul><li>ActiveMQ, Camel, Cxf, ServiceMix, FuseHQ </li></ul></ul></ul><ul><ul><li>Subscribe production and development support, Consulting, Virtual Training </li></ul></ul><ul><ul><li>Provide first class support: Emploies many Apache project co-founders and commiters </li></ul></ul><ul><ul><li>Provides Open Maven repositories (No need to contract support to gain access to supported and fixed versions) </li></ul></ul>www.xebia.fr / blog.xebia.fr
    11. 11. Competitors and Families of products <ul><li>ESB (Entreprise Service Bus): </li></ul><ul><ul><li>ServiceMix (JBI compliant, integrates Apache Camel) </li></ul></ul><ul><ul><li>JbossESB </li></ul></ul><ul><ul><li>WebSphereESB (SCA compliant) </li></ul></ul><ul><ul><li>SonicESB, OpenESB, Petals... </li></ul></ul><ul><li>Lightweight Enterprise Integration Patterns Frameworks: </li></ul><ul><ul><li>Camel </li></ul></ul><ul><ul><li>MuleESB </li></ul></ul><ul><ul><li>Spring Integration </li></ul></ul><ul><li>Process Servers, EAI, … </li></ul><ul><ul><li>WPS (Websphere Process Server) </li></ul></ul><ul><ul><li>Biztalk Server </li></ul></ul>www.xebia.fr / blog.xebia.fr
    12. 12. Camel compared to Mule ... <ul><li>Both based on Spring + POJO </li></ul><ul><li>They can run in standalone mode or embedded in an OSGI server, application server </li></ul><ul><li>They are not based on based on JBI specification </li></ul><ul><ul><li>Where the messages send over the bus are XML normalized messages </li></ul></ul><ul><li>Camel has more components than Mule now </li></ul><ul><li>Camel proposes a DSL Language </li></ul><ul><li>Mule has better monitoring & management tools </li></ul>www.xebia.fr / blog.xebia.fr
    13. 13. Camel compared to Mule ... <ul><li>You don't need to create a lot of XML config files with inbound/outbound stuff like you have to do in Mule. </li></ul><ul><li>The routing in Mule is not so intuitive and not appear directly in the XML or DSL </li></ul>www.xebia.fr / blog.xebia.fr
    14. 14. www.xebia.fr / blog.xebia.fr The basics
    15. 15. Message Routing www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget eros. Mauris scelerisque justo et ipsum scelerisque aliquam. In at auctor diam. Suspendisse ut justo sed diam Endpoint A Message
    16. 16. Camel Components www.xebia.fr / blog.xebia.fr
    17. 17. Kick Ass features <ul><li>Integrates with almost everything … </li></ul><ul><li>Support for: </li></ul><ul><ul><li>Scripting languages </li></ul></ul><ul><ul><ul><li>Groovy </li></ul></ul></ul><ul><ul><ul><li>Scala </li></ul></ul></ul><ul><ul><li>Google App Engine & Google APIs </li></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Built-in BAM Features </li></ul><ul><li>Extendable </li></ul>www.xebia.fr / blog.xebia.fr
    18. 18. Simple Routing www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget eros. Mauris scelerisque justo et ipsum scelerisque aliquam. In at auctor diam. Suspendisse ut justo sed diam Endpoint A Message File Jms
    19. 19. Pipeline www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget eros. Mauris scelerisque justo et ipsum scelerisque aliquam. In at auctor diam. Suspendisse ut justo sed diam Endpoint A Message Endpoint C Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget eros. Mauris scelerisque justo et ipsum scelerisque aliquam. In at auctor diam. Suspendisse ut justo sed diam Endpoint D Message Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget
    20. 20. Multicast www.xebia.fr / blog.xebia.fr Endpoint B Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed magna urna, varius a facilisis nec, sagittis eget eros. Mauris scelerisque justo et ipsum scelerisque aliquam. In at auctor diam. Suspendisse ut justo sed diam Endpoint A Message Endpoint B Endpoint B File IBatis SMTP SFTP
    21. 21. Message filter: Spring XML www.xebia.fr / blog.xebia.fr <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:schemaLocation = &quot;…&quot; > < camelContext xmlns = &quot;http://activemq.apache.org/camel/schema/spring&quot; > < route > < from uri = &quot;activemq:topic:Quotes&quot; /> < filter > < xpath > /quote/product = ‘widget’ </ xpath > < to uri = &quot;mqseries:WidgetQuotes&quot; /> </ filter > </ route > </ camelContext > </ beans >
    22. 22. Message filter: Java DSL www.xebia.fr / blog.xebia.fr package com.acme.quotes; import org.apache.camel.builder.RouteBuilder; public class MyRouteBuilder extends RouteBuilder { public void configure() { // forward widget quotes to MQSeries from( &quot;activemq:topic:Quotes&quot; ). filter().xpath( &quot;/quote/product = ‘widget’&quot; ). to( &quot;mqseries:WidgetQuotes&quot; ); } }
    23. 23. Content Based Router: Java www.xebia.fr / blog.xebia.fr from( &quot;activemq:NewOrders&quot; ). choice().when().xpath( &quot;/quote/product = 'widget'&quot; ). to( &quot;activemq:Orders.Widgets&quot; ). choice().when().xpath( &quot;/quote/product = 'gadget'&quot; ). to( &quot;activemq:Orders.Gadgets&quot; ). otherwise(). to( &quot;activemq:Orders.Bad&quot; );
    24. 24. Content Based Router: Spring XML www.xebia.fr / blog.xebia.fr <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < beans xmlns = &quot;http://www.springframework.org/schema/beans&quot; xmlns:xsi = &quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:schemaLocation = &quot;...&quot; > < camelContext xmlns = &quot;http://activemq.apache.org/camel/schema/spring&quot; > < route > < from uri = &quot;activemq:NewOrders&quot; /> < choice > < when > < xpath > /order/product = 'widget' </ xpath > < to uri = &quot;activemq:Orders.Widgets&quot; /> </ when > < when > < xpath > /order/product = 'gadget' </ xpath > < to uri = &quot;activemq:Orders.Gadgets&quot; /> </ when > < otherwise > < to uri = &quot;activemq:Orders.Bad&quot; /> </ otherwise > </ choice > </ route > </ camelContext > </ beans >
    25. 25. How camel do this routing work ? <ul><li>Camel Components </li></ul><ul><ul><li>Camel Endpoints </li></ul></ul><ul><ul><ul><li>Camel Consumer </li></ul></ul></ul><ul><ul><ul><li>Camel Producer </li></ul></ul></ul><ul><li>Camel-Core </li></ul>www.xebia.fr / blog.xebia.fr
    26. 26. Message processors www.xebia.fr / blog.xebia.fr from( &quot;direct:start&quot; ).process( new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String. class ) + &quot; World!&quot; ); } }).to( &quot;mock:result&quot; ); < bean id = &quot;myProcessor&quot; class = &quot;com.acme.MyProcessor&quot; /> from( &quot;activemq:myQueue&quot; ).to( &quot;myProcessor&quot; ); <ul><li>The Processor interface is used to implement: </li></ul><ul><ul><li>Consumers of message exchanges </li></ul></ul><ul><ul><li>A Message Translator </li></ul></ul>
    27. 27. Expressions www.xebia.fr / blog.xebia.fr <ul><li>Camel supports pluggable Expression strategies using a variety of different Languages (Dynamic rules): </li></ul><ul><ul><li>Bean Language for using Java for expressions </li></ul></ul><ul><ul><li>The unified EL from JSP and JSF </li></ul></ul><ul><ul><li>JXPath, Mvel, OGNL </li></ul></ul><ul><ul><li>Scala DSL, Groovy </li></ul></ul><ul><ul><li>Python, PHP, Ruby, JavaScript </li></ul></ul><ul><ul><li>Simple, Constant </li></ul></ul><ul><ul><li>Xpath, Xquery, SQL </li></ul></ul>
    28. 28. Predicates www.xebia.fr / blog.xebia.fr <ul><li>Camel supports a pluggable interface called Predicate </li></ul><ul><ul><li>Can be used to integrate a dynamic predicate into Enterprise Integration Patterns such as when using: </li></ul></ul><ul><ul><ul><li>Message Filter </li></ul></ul></ul><ul><ul><ul><li>Content Based Router. </li></ul></ul></ul><ul><li>A Predicate is being evaluated to a boolean value so the result is either true or false. </li></ul><ul><ul><li>This makes Predicate so powerful as it is often used to control the routing of message in which path they should be routed. </li></ul></ul>
    29. 29. Predicates examples www.xebia.fr / blog.xebia.fr from( &quot;jms:queue:order&quot; ) .choice() .when(header( &quot;type&quot; ).isEqualTo( &quot;widget&quot; )).to( &quot;bean:widgetOrder&quot; ) .when(header( &quot;type&quot; ).isEqualTo( &quot;wombat&quot; )).to( &quot;bean:wombatOrder&quot; ) .otherwise() .to( &quot;bean:miscOrder&quot; ) .end(); Predicate isWidget = header( &quot;type&quot; ).isEqualTo( &quot;widget&quot; ); from( &quot;jms:queue:order&quot; ) .choice() .when( isWidget ).to( &quot;bean:widgetOrder&quot; ) .when( isWombat ).to( &quot;bean:wombatOrder&quot; ) .otherwise() .to( &quot;bean:miscOrder&quot; ) .end();
    30. 30. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Transaction Manager </li></ul><ul><li>< bean id = &quot;jmsTransactionManager&quot; class = &quot;org.springframework.jms.connection.JmsTransactionManager&quot; > </li></ul><ul><li>< property name = &quot;connectionFactory&quot; ref = &quot;jmsConnectionFactory&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li>< bean id = &quot;jmsConnectionFactory&quot; class = &quot;org.apache.activemq.ActiveMQConnectionFactory&quot; > </li></ul><ul><li>< property name = &quot;brokerURL&quot; value = &quot;tcp://localhost:61616&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li>Transaction Policies </li></ul><ul><li>< bean id = &quot;PROPAGATION_REQUIRED&quot; class = &quot;org.apache.camel.spring.spi.SpringTransactionPolicy&quot; > </li></ul><ul><li>< property name = &quot;transactionManager&quot; ref = &quot;jmsTransactionManager&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li>< bean id = &quot;PROPAGATION_REQUIRES_NEW&quot; class = &quot;org.apache.camel.spring.spi.SpringTransactionPolicy&quot; > </li></ul><ul><li>< property name = &quot;transactionManager&quot; ref = &quot;jmsTransactionManager&quot; /> </li></ul><ul><li>< property name = &quot;propagationBehaviorName&quot; value = &quot;PROPAGATION_REQUIRES_NEW&quot; /> </li></ul><ul><li></ bean > </li></ul>
    31. 31. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Java DSL (1) </li></ul><ul><li>public void configure() { </li></ul><ul><li> ... </li></ul><ul><li> Policy requried = bean ( SpringTransactionPolicy . class , &quot;PROPAGATION_REQUIRED&quot; ) ) ; </li></ul><ul><li> Policy requirenew = bean ( SpringTransactionPolicy . class , &quot;PROPAGATION_REQUIRES_NEW&quot; )); </li></ul><ul><li> ... </li></ul><ul><li>} </li></ul><ul><li> // Send to bar in a new transaction </li></ul><ul><li> from( &quot;activemq:queue:foo&quot; ) .policy(requirenew).to( &quot;activemq:queue:bar&quot; ) ; </li></ul><ul><li> // Send to bar without a transaction. </li></ul><ul><li> from( &quot;activemq:queue:foo&quot; ).policy(notsupported).to( &quot;activemq:queue:bar&quot; ); </li></ul>
    32. 32. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Java DSL (2) </li></ul><ul><li>from( &quot;direct:mixed&quot; ) </li></ul><ul><li>// using required </li></ul><ul><li>.transacted( &quot;PROPAGATION_REQUIRED&quot; ) </li></ul><ul><li>// all these steps will be okay </li></ul><ul><li>.setBody(constant( &quot;Tiger in Action&quot; )).beanRef( &quot;bookService&quot; ) </li></ul><ul><li>.setBody(constant( &quot;Elephant in Action&quot; )).beanRef( &quot;bookService&quot; ) </li></ul><ul><li>.setBody(constant( &quot;Lion in Action&quot; )).beanRef( &quot;bookService&quot; ) </li></ul><ul><li>// continue on route 2 </li></ul><ul><li>.to( &quot;direct:mixed2&quot; ) ; </li></ul><ul><li>from( &quot;direct:mixed2&quot; ) </li></ul><ul><li>// using a different propagation which is requires new </li></ul><ul><li>.transacted( &quot;PROPAGATION_REQUIRES_NEW&quot; ) </li></ul><ul><li>// tell Camel that if this route fails then only rollback this last route </li></ul><ul><li>// by using ( rollback only *last*) </li></ul><ul><li>.onException(Exception. class ).markRollbackOnlyLast().end() </li></ul><ul><li>// this step will be okay </li></ul><ul><li>.setBody(constant( &quot;Giraffe in Action&quot; )).beanRef( &quot;bookService&quot; ) </li></ul><ul><li>// this step will fail with donkey </li></ul><ul><li>.setBody(constant( &quot;Donkey in Action&quot; )).beanRef( &quot;bookService&quot; ); </li></ul>
    33. 33. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Spring XML (1) </li></ul><ul><li><!-- here we define our camel context --> </li></ul><ul><li>< camel:camelContext id = &quot;myroutes&quot; > </li></ul><ul><li><!-- first route with transaction error handler --> </li></ul><ul><li><!-- here we refer to our transaction error handler we define in this Spring XML file --> </li></ul><ul><li><!-- in this route the transactionErrorHandler is used --> </li></ul><ul><li>< camel:route errorHandlerRef = &quot;transactionErrorHandler&quot; > </li></ul><ul><li><!-- 1: from the jms queue --> </li></ul><ul><li>< camel:from uri = &quot;activemq:queue:okay&quot; /> </li></ul><ul><li><!-- 2: setup the transactional boundaries to require a transaction --> </li></ul><ul><li>< camel:transacted ref = &quot;required&quot; /> </li></ul><ul><li><!-- 3: call our business logic that is myProcessor --> </li></ul><ul><li>< camel:process ref = &quot;myProcessor&quot; /> </li></ul><ul><li><!-- 4: if success then send it to the mock --> </li></ul><ul><li>< camel:to uri = &quot;mock:result&quot; /> </li></ul><ul><li></ camel:route > </li></ul><ul><li><!-- 2nd route with no error handling --> </li></ul><ul><li><!-- this route doens't use error handler, in fact the spring bean with id noErrorHandler --> </li></ul><ul><li>< camel:route errorHandlerRef = &quot;noErrorHandler&quot; > </li></ul><ul><li>< camel:from uri = &quot;activemq:queue:bad&quot; /> </li></ul><ul><li>< camel:to uri = &quot;log:bad&quot; /> </li></ul><ul><li></ camel:route > </li></ul><ul><li></ camel:camelContext > </li></ul>
    34. 34. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>Using policies in Spring XML (2) </li></ul><ul><li><!-- camel policy we refer to in our route --> </li></ul><ul><li>< bean id = &quot;required&quot; class = &quot;org.apache.camel.spring.spi.SpringTransactionPolicy&quot; > </li></ul><ul><li>< property name = &quot;transactionTemplate&quot; ref = &quot;PROPAGATION_REQUIRED&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li><!-- the standard spring transaction template for required --> </li></ul><ul><li>< bean id = &quot;PROPAGATION_REQUIRED&quot; class = &quot;org.springframework.transaction.support.TransactionTemplate&quot; > </li></ul><ul><li>< property name = &quot;transactionManager&quot; ref = &quot;jmsTransactionManager&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li><!-- the transaction error handle we refer to from the route --> </li></ul><ul><li>< bean id = &quot;transactionErrorHandler&quot; class = &quot;org.apache.camel.spring.spi.TransactionErrorHandlerBuilder&quot; > </li></ul><ul><li>< property name = &quot;transactionTemplate&quot; ref = &quot;PROPAGATION_REQUIRED&quot; /> </li></ul><ul><li></ bean > </li></ul><ul><li><!-- the no error handler --> </li></ul><ul><li>< bean id = &quot;noErrorHandler&quot; class = &quot;org.apache.camel.builder.NoErrorHandlerBuilder&quot; /> </li></ul>
    35. 35. Transaction Oriented Endpoints www.xebia.fr / blog.xebia.fr <ul><li>TransactionErrorHandler </li></ul><ul><li>onException ( ValidationException . class ).handled( true ).transform(body( constant ( &quot;INVALID ORDER&quot; ))); </li></ul><ul><li>from ( &quot;jetty: http://localhost/myservice/order &quot; ) </li></ul><ul><li>.transacted() </li></ul><ul><li>.to( &quot;bean:validateOrder&quot; ) </li></ul><ul><li>.to( &quot;jms:queue:order&quot; ); </li></ul><ul><li>e rrorHandler( transactionErrorHandler() . maximumRedeliveries(6) ) ; </li></ul><ul><li>onException(IllegalArgumentException. class ).maximumRedeliveries(4); </li></ul><ul><li>from( &quot;direct:okay&quot; ) </li></ul><ul><li>.transacted() </li></ul><ul><li>.setBody(constant( &quot;Tiger in Action&quot; )).beanRef( &quot;bookService&quot; ) </li></ul><ul><li>.setBody(constant( &quot;Elephant in Action&quot; )).beanRef( &quot;bookService&quot; ); </li></ul>
    36. 36. DefaultErrorHandler & DeadLetterChannel www.xebia.fr / blog.xebia.fr <ul><li>Client notified (Default DLC behavior, not DEH ) </li></ul><ul><li>errorHandler(deadLetterChannel( &quot;jms:queue:dead&quot; ). </li></ul><ul><li>maximumRedeliveries(3).redeliverDealy(5000)); </li></ul><ul><li>Client not notified </li></ul><ul><li>errorHandler(deadLetterChannel( &quot;jms:queue:dead&quot; ). </li></ul><ul><li>maximumRedeliveries(3).redeliverDealy(5000).handled( false )); </li></ul><ul><li>Use original message </li></ul><ul><li>errorHandler(deadLetterChannel( &quot;jms:queue:dead&quot; ) </li></ul><ul><li> .useOriginalMessage().mamimumRedeliveries(5).redeliverDelay(5000 ); </li></ul><ul><li>Using default error handler </li></ul><ul><li>onException(ValidationException. class ).handled( true ).transform(body(constant( &quot;INVALID ORDER&quot; ))); </li></ul>
    37. 37. Annotation support www.xebia.fr / blog.xebia.fr <ul><li>Camel supports annotations </li></ul><ul><li>public class RouterBean { </li></ul><ul><li>@Consume (uri = &quot;activemq:foo&quot; ) </li></ul><ul><li>@RecipientList </li></ul><ul><li>public String[] route(String body) { </li></ul><ul><li>return new String[]{ &quot;activemq:bar&quot; , &quot;activemq:whatnot&quot; }; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>public class Foo { </li></ul><ul><li>@ MessageDriven ( uri = &quot;activemq:my.queue&quot; ) </li></ul><ul><li>public void doSomething( @XPath ( &quot;/foo/bar/text()&quot; ) String correlationID, @Body String body) { </li></ul><ul><li>// process the inbound message here </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
    38. 38. @Bean annotation www.xebia.fr / blog.xebia.fr public class Foo { @ MessageDriven ( uri = &quot;activemq:my.queue&quot; ) public void doSomething( @Bean ( &quot;myCorrelationIdGenerator&quot; ) String correlationID, @Body String body) { // process the inbound message here } } public class MyIdGenerator { private UserManager userManager ; public String generate( @ Header ( name = &quot;user&quot; ) String user, @Body String payload) throws Exception { User user = userManager .lookupUser(user); String id = user.getPrimaryId() + generateHashCodeForPayload (payload); return id; } }
    39. 39. Groovy support www.xebia.fr / blog.xebia.fr <ul><li>Using Java DSL </li></ul><ul><li>// lets route if a line item is over $100 </li></ul><ul><li>from( &quot;queue:foo&quot; ).filter( groovy ( &quot;request.lineItems.any { i -> i.value > 100 }&quot; )).to( &quot;queue:bar&quot; ); </li></ul><ul><li>Using Spring XML </li></ul><ul><li>< route > </li></ul><ul><li>< from uri = &quot;queue:foo&quot; /> </li></ul><ul><li>< filter > </li></ul><ul><li>< groovy > request.lineItems.any { i -> i.value > 100 } </ groovy > </li></ul><ul><li>< to uri = &quot;queue:bar&quot; /> </li></ul><ul><li></ filter > </li></ul><ul><li></ route > </li></ul>
    40. 40. Testing with camel www.xebia.fr / blog.xebia.fr <ul><li>Testing of distributed and asynchronous processing is notoriously difficult </li></ul><ul><li>Camel provides helpers: </li></ul><ul><ul><li>Test URIs </li></ul></ul><ul><ul><li>Datasets </li></ul></ul><ul><ul><li>Mocks </li></ul></ul><ul><li>Maven dependency for tests: </li></ul><ul><li>< dependency > </li></ul><ul><li>< groupId > org.apache.camel </ groupId > </li></ul><ul><li>< artifactId > camel-test </ artifactId > </li></ul><ul><li>< version > ${camel-version} </ version > </li></ul><ul><li>< scope > test </ scope > </li></ul><ul><li></ dependency > </li></ul>
    41. 41. Testing with camel www.xebia.fr / blog.xebia.fr public class FilterTest extends CamelTestSupport { @EndpointInject (uri = &quot;mock:result&quot; ) protected MockEndpoint resultEndpoint ; @Produce (uri = &quot;direct:start&quot; ) protected ProducerTemplate template ; public void testSendMatchingMessage() throws Exception { String expectedBody = &quot;<matched/>&quot; ; resultEndpoint .expectedBodiesReceived(expectedBody); template .sendBodyAndHeader(expectedBody, &quot;foo&quot; , &quot;bar&quot; ); resultEndpoint .assertIsSatisfied(); } public void testSendNotMatchingMessage() throws Exception { resultEndpoint .expectedMessageCount(0); template .sendBodyAndHeader( &quot;<notMatched/>&quot; , &quot;foo&quot; , &quot;notMatchedHeaderValue&quot; ); resultEndpoint .assertIsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from( &quot;direct:start&quot; ).filter(header( &quot;foo&quot; ).isEqualTo( &quot;bar&quot; )).to( &quot;mock:result&quot; ); } }; } }
    42. 42. Spring Test with Java Config www.xebia.fr / blog.xebia.fr @ ContextConfiguration ( locations = &quot;org.apache.camel.spring.javaconfig.patterns.FilterTest$ContextConfig&quot; , loader = JavaConfigContextLoader . class ) public class FilterTest extends AbstractJUnit4SpringContextTests { @EndpointInject (uri = &quot;mock:result&quot; ) protected MockEndpoint resultEndpoint ; @Produce (uri = &quot;direct:start&quot; ) protected ProducerTemplate template ; @ DirtiesContext @Test public void testSendMatchingMessage() throws Exception { String expectedBody = &quot;<matched/>&quot; ; resultEndpoint .expectedBodiesReceived(expectedBody); template .sendBodyAndHeader(expectedBody, &quot;foo&quot; , &quot;bar&quot; ); resultEndpoint .assertIsSatisfied(); } @ Configuration public static class ContextConfig extends SingleRouteCamelConfiguration { @Bean public RouteBuilder route() { return new RouteBuilder() { public void configure() { from( &quot;direct:start&quot; ).filter(header( &quot;foo&quot; ).isEqualTo( &quot;bar&quot; )).to( &quot;mock:result&quot; ); } }; } } }
    43. 43. Camel riding from Java <ul><li>/META-INF/spring/camelContext.xml </li></ul><ul><li>Set the CLASSPATH </li></ul><ul><li>Run Camel context from : </li></ul><ul><ul><li>java org.apache.camel.spring.Main </li></ul></ul>www.xebia.fr / blog.xebia.fr
    44. 44. Camel & Maven <ul><li>mvn camel:run, camel:dot </li></ul><ul><li>Maven declaration: </li></ul>www.xebia.fr / blog.xebia.fr <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < project > < build > < plugins > < plugin > < groupId > org.apache.camel </ groupId > < artifactId > camel- maven-plugin </ artifactId > </ plugin > </ plugins > </ build > < reporting > < plugins > < plugin > < groupId > org.apache.camel </ groupId > < artifactId > camel- maven-plugin </ artifactId > </ plugin > </ plugins > </ reporting > </ project >  
    45. 45. Maven site report <ul><li>Result of report plugin (Dot & GraphViz) </li></ul>www.xebia.fr / blog.xebia.fr
    46. 46. Where would I use Camel ? <ul><li>Standalone or in any Spring application </li></ul><ul><li>Inside ActiveMQ’s JMS client or the broker </li></ul><ul><li>Inside your ESB such as ServiceMix via the servicemix-camel Service Unit </li></ul><ul><li>Inside CXF either as a transport or reusing CXF inside Camel </li></ul>www.xebia.fr / blog.xebia.fr
    47. 47. www.xebia.fr / blog.xebia.fr Going further with Apache Camel …
    48. 48. Books <ul><li>Theme: </li></ul><ul><ul><li>This book is essentially the Camel bible </li></ul></ul><ul><li>Edition: </li></ul><ul><ul><li>Manning </li></ul></ul><ul><ul><li>Fall 2010 | 435 pages </li></ul></ul><ul><ul><li>ISBN: 9781935182368 </li></ul></ul><ul><li>Authors: </li></ul><ul><ul><li>Claus Ibsen, Committer and lead </li></ul></ul><ul><ul><li>Jonathan Anstey, Committer </li></ul></ul><ul><ul><li>Hadrian Zbarcea, Committer, Chair of PMC and Release Manager </li></ul></ul>www.xebia.fr / blog.xebia.fr
    49. 49. Books <ul><li>Theme: </li></ul><ul><ul><li>catalog of sixty-five patterns, with real-world solutions </li></ul></ul><ul><li>Edition: </li></ul><ul><ul><li>Addison-Wesley Professional </li></ul></ul><ul><ul><li>October 2003 | 736 pages </li></ul></ul><ul><ul><li>ISBN: 9780321200686 </li></ul></ul><ul><li>Authors: </li></ul><ul><ul><li>Gregor Hohpe, Software engineer at Google. </li></ul></ul><ul><ul><li>Bobby Woolf, WebSphere consultant at IBM. </li></ul></ul>www.xebia.fr / blog.xebia.fr
    50. 50. www.xebia.fr / blog.xebia.fr Twitter: @alexiskinsella Thank You
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×