DOSUG Taking Apache Camel For A Ride

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    6 Favorites & 1 Group

    DOSUG Taking Apache Camel For A Ride - Presentation Transcript

    1. Taking Apache Camel For a Ride Bruce Snyder bsnyder@apache.org 3 June 2008 1
    2. Integration is Messy! 2
    3. System Integration 3
    4. Data Formats 4
    5. Apache Camel http://activemq.apache.org/camel/ 5
    6. What is Apache Camel? 6
    7. Enterprise Integration Patterns http://enterpriseintegrationpatterns.com/ 7
    8. Patterns 8
    9. Message Routing 9
    10. Language Support • BeanShell • SQL • Javascript • XPath • Groovy • XQuery • Python • OGNL • PHP • JSR 223 scripting • Ruby 10
    11. Apache Camel Components http://activemq.apache.org/camel/components.html 11
    12. History of Apache Camel 12
    13. The Camel Context CamelContext context = new DefaultCamelContext(); context.addRoutes(new MyRouteBuilder()); context.start(); <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <package>com.acme.quotes</package> </camelContext> 13
    14. Pattern Examples 14
    15. Patterns Again 15
    16. Content Based Router RouteBuilder builder = new RouteBuilder() { public void configure() { from(\"seda:a\").choice().when(header(\"foo\") .isEqualTo(\"bar\")).to(\"seda:b\") .when(header(\"foo\").isEqualTo(\"cheese\")) .to(\"seda:c\").otherwise().to(\"seda:d\"); } }; 16
    17. Content Based Router <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <route> <from uri=\"activemq:NewOrders\"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri=\"activemq:Orders.Widgets\"/> </when> <when> <xpath>/order/product = 'gadget'</xpath> <to uri=\"activemq:Orders.Gadgets\"/> </when> <otherwise> <to uri=\"activemq:Orders.Bad\"/> </otherwise> </choice> </route> </camelContext> 17
    18. Message Filter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"activemq:topic:Quotes). filter().xpath(\"/quote/product = ‘widget’\"). to(\"mqseries:WidgetQuotes\"); } } 18
    19. Message Filter <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <route> <from uri=\"activemq:topic:Quotes\"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri=\"mqseries:WidgetQuotes\"/> </filter> </route> </camelContext> 19
    20. Splitter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"file://orders\"). splitter(body().tokenize(\"\\n\")). to(\"activemq:Order.Items\"); } } 20
    21. Splitter Using XQuery public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"file://orders\"). splitter().xquery(\"/order/items\"). to(\"activemq:Order.Items\"); } } 21
    22. Aggregator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"activemq:Inventory.Items\"). aggregator().xpath(\"/order/@id\"). to(\"activemq:Inventory.Order\"); } } 22
    23. Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"file://incoming”). to(\"xslt:com/acme/mytransform.xsl\"). to(\"http://outgoing.com/foo\"); } } 23
    24. Resequencer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"direct:a”). resequencer(header(\"JMSPriority\")). to(\"seda:b\"); } } 24
    25. Throttler public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"seda:a”). throttler(3).timePeriodMillis(30000). to(\"seda:b\"); } } 25
    26. Delayer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"seda:a”). delayer(header(\"JMSTimestamp\", 3000). to(\"seda:b\"); } } 26
    27. Combine Patterns public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"seda:a”). resequencer(header(\"JMSPriority\")). delayer(3000). to(\"seda:b\"); } } 27
    28. Beans 28
    29. Bean package com.mycompany.beans; public class MyBean { public void someMethod(String name) { ... } } <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <package>com.mycompany.beans</package> </camelContext> 29
    30. Bean as a Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"activemq:Incoming”). beanRef(\"myBean\"). to(\"activemq:Outgoing\"); } } 30
    31. Bean as a Message Translator *With Method Name public class MyRouteBuilder extends RouteBuilder { public void configure() { from(\"activemq:Incoming”). beanRef(\"myBean\", \"someMethod\"). to(\"activemq:Outgoing\"); } } 31
    32. Type Conversion 32
    33. Type Conversion @Converter public class IOConverter { @Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream( new FileInputStream(file)); } } 33
    34. Binding Beans to Camel Endpoints public class Foo { @MessageDriven(uri=\"activemq:cheese\") public void onCheese(String name) { ... } } 34
    35. Binding Method Arguments public class Foo { public void onCheese( @XPath(\"/foo/bar\") String name, @Header(\"JMSCorrelationID\") String id) { ... } } http://activemq.apache.org/camel/bean-integration.html 35
    36. Injecting Endpoints Into Beans public class Foo { @EndpointInject(uri=\"activemq:foo.bar\") ProducerTemplate producer; public void doSomething() { if (whatever) { producer.sendBody(\"<hello>world!</hello>\"); } } } 36
    37. Spring Remoting - Server Side <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <export id=\"sayService\" uri=\"activemq:MyService\" serviceRef=\"sayImpl\" serviceInterface=\"com.acme.MyServiceInterface\"/> </camelContext> <bean id=\"sayImpl\" class=\"com.acme.MyServiceImpl\"/> 37
    38. Spring Remoting - Client Side <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <proxy id=\"sayService\" serviceUrl=\"activemq:MyService\" serviceInterface=\"com.acme.MyServiceInterface\"/> </camelContext> 38
    39. Dependency Injection <camelContext xmlns=\"http://activemq.apache.org/camel/schema/spring\"> ... </camelContext> <bean id=\"activemq\" class=\"org.apache.camel.component.jms.JmsComponent\"> <property name=\"connectionFactory\"> <bean class=\"org.apache.activemq.ActiveMQConnectionFactory\"> <property name=\"brokerURL\" value=\"vm://localhost?broker.persistent=false\"/> </bean> </property> </bean> 39
    40. Business Activity Monitoring (BAM) 40
    41. Business Activity Monitoring (BAM) public class MyActivities extends ProcessBuilder { public void configure() throws Exception { // lets define some activities, correlating on an // XPath query of the message body ActivityBuilder purchaseOrder = activity(\"activemq:PurchaseOrders\") .correlate(xpath(\"/purchaseOrder/@id\").stringResult()); ActivityBuilder invoice = activity(\"activemq:Invoices\") .correlate(xpath(\"/invoice/@purchaseOrderId\").stringResult()); // now lets add some BAM rules invoice.starts().after(purchaseOrder.completes()) .expectWithin(seconds(1)) .errorIfOver(seconds(2)).to(\"activemq:FailedProcesses\"); } } 41
    42. Ride the Camel! 42
    43. Questions? 43

    + Matthew McCulloughMatthew McCullough, 2 years ago

    custom

    3369 views, 6 favs, 0 embeds more stats

    Bruce Snyder's excellent talk on Apache Camel to th more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3369
      • 3369 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 6
    • Downloads 62
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories