1 / 41

Making integration easy with Apache Camel

Making integration easy with Apache Camel. Tijs Rademakers. Whoami. Software Architect at Atos Origin Focus on integration challenges ESB and SOA technology WebSphere Process Server, WebSphere ESB Mule, ServiceMix, Camel, Synapse, Tuscany Open Source ESBs in Action www.esbinaction.com

galena
Télécharger la présentation

Making integration easy with Apache Camel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Making integration easy with Apache Camel Tijs Rademakers

  2. Whoami • Software Architect at Atos Origin • Focus on integration challenges • ESB and SOA technology • WebSphere Process Server, WebSphere ESB • Mule, ServiceMix, Camel, Synapse, Tuscany • Open Source ESBs in Action • www.esbinaction.com • All chapters available (MEAP) • Expected print date: August 2008 • For questions and remarks: tijs@apache.org

  3. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  4. Yet another framework? Apache Camel goals Provide an easy to use integration framework No container dependency No heavy specification as starting point Implement Enterprise Integration Patterns Lots of connectivity options “A camel can carry 4 times as much load as other beasts of burden”

  5. Apache Camel intro • Sub-project of Apache ActiveMQ • http://activemq.apache.org/camel • Production release: 1.3.0 (April 2008) • Java DSL, Spring XML configuration • Lots of connectivity options • JMS, File, JPA, CXF, JBI, FTP

  6. Pattern support

  7. Component support

  8. Fluent API • Camel DSL implements a Fluent API • Introduced by Martin Fowler, Eric Evans • API which is readable and “flows” private void makeOrder(Customer customer) { Order o1 = new Order(); customer.addOrder(o1); OrderLine line1 = new OrderLine(6, Product.find(“LAPTOP")); o1.addLine(line1); OrderLine line2 = new OrderLine(5, Product.find(“HARDDISK")); o1.addLine(line2); line2.setSkippable(true); }

  9. Fluent API order example private void makeOrder(Customer customer) { customer.newOrder() .with(6, “LAPTOP") .with(5, “HARDDISK").skippable(); }

  10. Example of Camel Fluent API from(“activemq:in.queue”) .to(“log://IncomingMessageInQueue?level=info”) .setHeader(“api”, “fluent”) .to(“file://test”);

  11. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  12. Simple example

  13. Implement some routing public class InsuranceRouteBuilder extends RouteBuilder { public void configure() { from("file://InsuranceInbox").convertBodyTo(String.class) .choice() .when().xpath("/insurance-request='Travel'") .to("activemq:travel.queue") .when().xpath("/insurance-request='House'") .to("activemq:house.queue") .otherwise() .to("activemq:other.queue"); } }

  14. Now start-up this example CamelContext context = new DefaultCamelContext(); context.addRoutes(new InsuranceRouteBuilder()); context.addComponent(“activemq”, activeMQComponent(“tcp://localhost:61616”); context.start();

  15. And send some test messages CamelTemplate template = new CamelTemplate(context); template.sendBody(“file://Insurance”, “<insurance-request>Travel</insurance-request”);

  16. Integrate with Spring <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://activemq.apache.org/camel/schema/spring"> <camel:camelContext id="camel"> <camel:package> com.atosorigin.nljug.insurance.router </camel:package> </camel:camelContext> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="brokerURL" value="tcp://localhost:61616"/> </bean> </beans>

  17. Now start-up this example ApplicationContext appContext = new ClassPathXmlApplicationContext(“camel-context.xml”); CamelContext camelContext = SpringCamelContext.springCamelContext(appContext); camelContext.start();

  18. To test we need a listener public class InsuranceListener { @MessageDriven(uri="activemq:travel.queue") public void onTravel(String message) { System.out.println("received travel insurance request " + message); } @MessageDriven(uri="activemq:house.queue") public void onHouse(String message) { System.out.println("received house insurance request " + message); } @MessageDriven(uri="activemq:other.queue") public void onOther(String message) { System.out.println("received other insurance request " + message); } }

  19. Register this listener <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://activemq.apache.org/camel/schema/spring"> <camel:camelContext id="camel"> <camel:package> com.atosorigin.nljug.insurance.router </camel:package> </camel:camelContext> <bean class=“com.atosorigin.nljug.insurance.listener.InsuranceListener”/> // activemq broker </beans>

  20. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  21. Same example

  22. Now in XML format <camelContext id="camel“ xmlns=“http://activemq.apache.org/camel/schema/spring”> <route> <from uri="file://InsuranceInbox"/> <choice> <when> <xpath>/insurance-request='Travel'</xpath> <to uri="activemq:travel.queue"/> </when> <when> <xpath>/insurance-request='House'</xpath> <to uri="activemq:house.queue"/> </when> <otherwise><to uri="activemq:other.queue"/></otherwise> </choice> </route> </camelContext>

  23. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  24. Message filter with demo

  25. Message filter implementation public class InsuranceFilter extends RouteBuilder { public void configure() { from("activemq:inbox.queue") .filter(header("insurancetype").isEqualTo("Travel")) .to("activemq:travel.queue"); } }

  26. Filter XML implementation <camelContext id=“camel” xmlns=“http://activemq.apache.org/camel/schema/spring”> <route> <from uri=“activemq:inbox.queue”/> <filter> <groovy>in.headers.insurancetype==‘Travel’</groovy> <to uri=“activemq:travel.queue”/> </filter> </route> </camelContext>

  27. Recipient list

  28. Recipient list implementation public class InsuranceRecipientList extends RouteBuilder { public void configure() { from("activemq:list.queue") .to("activemq:queue1") .to("activemq:queue2"); } }

  29. Dynamic Recipient list (XML) <camelContext id=“camel” xmlns=“http://activemq.apache.org/camel/schema/spring”> <route> <from uri=“activemq:list.queue”/> <recipientList> <groovy>in.headers.recipients</groovy> </recipientList> </route> </camelContext>

  30. Interact with a bean public class InsuranceBean { public void processRequest(String request) { System.out.println(“received “ + request); } } public class InsuranceBeanRouter extends RouteBuilder { public void configure() { from("activemq:bean.in") .bean(new InsuranceBean()) .to("activemq:bean.out"); } }

  31. Interact with a bean method public class InsuranceMethodBean { public String processRequest(String name) { System.out.println("received " + name); return returnMessage(name); } public String returnMessage(String name) { return "hello " + name; } }

  32. Bean XML implementation <beans> <camelContext id=“camel” xmlns=“http://activemq.apache.org/camel/schema/spring”> <route> <from uri=“activemq:bean.in”/> <bean ref=“nameBean” method=“processRequest”/> <to uri=“activemq:bean.out”/> </route> </camelContext> <bean id=“nameBean” class=“com...insurance.bean.InsuranceMethodBean”/> </beans>

  33. Validation example public class InsuranceValidation extends RouteBuilder { public void configure() { from("activemq:validation.queue") .tryBlock() .to("validator:insurance.xsd") .to("activemq:validation.succeeded") .handle(ValidationException.class) .to("activemq:validation.failed"); } }

  34. Business Activity Monitoring public class InsuranceActivity extends ProcessBuilder { public void configure() throws Exception { ActivityBuilder purchaseOrder = activity(“jms:purchase.in") .correlate(xpath("/purchaseOrder/@id").stringResult()); ActivityBuilder invoice = activity(“jms:invoice.in") .correlate(xpath("/invoice/@purchaseOrderId").stringResult()); invoice.starts().after(purchaseOrder.completes()) .expectWithin(seconds(2)) .errorIfOver(seconds(4)).to("log:BAMFailure?level=error") } }

  35. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  36. Camel with Apache ServiceMix JBI Container CBR SE BPEL SE Camel SE Deployment Normalized Message Router Management JMS BC File BC WS BC Mail BC Monitoring Web Service JMS queue

  37. Camel Service Unit JBI Container Service Assembly jbi.xml deploy Service Engine Camel Service Unit NMR camel-context.xml JMS Service Unit Binding Component

  38. Reference JBI service in Camel public class InsuranceJBI extends RouteBuilder { public void configure() { from(“jbi:service:http://nljug.org/InsuranceInService") .filter(header("insurancetype").isEqualTo("Travel")) .to("jbi:service:http://nljug.org/TravelService"); } } <jms:consumer service=“jug:jmsConsumer" endpoint="endpoint" targetService=“jug:InsuranceInService" destinationName=“inbox.queue" connectionFactory="#connectionFactory"

  39. Agenda Introduction into Apache Camel Using a Java DSL Do you like XML better? Mediation examples Integration with Apache ServiceMix Summary and questions

  40. Summary • Apache Camel  ease of development • Java DSL or Fluent API / XML configuration • Pattern support • Automatic type converters • Apache Camel can be used in any application needing integration functionality • Simple start-up, small footprint • Apache Camel can be integrated with: • ActiveMQ, ServiceMix, CXF

  41. Questions?

More Related