Riding Apache Camel

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

    2 Favorites

    Riding Apache Camel - Presentation Transcript

    1. Riding Apache Camel Willem Jiang ningjiang@apache.org 2008-12
    2. About author • Apache CXF commiter and PMC member • Apache Camel commiter and PMC member • ningjiang@apache.org
    3. Riding Apache Camel •What's Camel •EIP Examples •Beans, Type Conversion , Data Format •Some tips of Camel Riding
    4. What is Camel? http://activemq.apache.org/camel/
    5. What is Camel? • A Camel can carry 4 times as much load as other beasts of burden! • Apache Camel is a powerful Spring based Integration Framework. • Camel implements the Enterprise Integration Patterns allowing you to configure routing and mediation rules in either a Java based Domain Specific Language (or Fluent API) or via Spring based Xml Configuration files. Either approaches mean you get smart completion of routing rules in your IDE whether in your Java or XML editor. • Apache Camel uses URIs so that it can easily work directly with any kind of Transport or messaging model such as HTTP, ActiveMQ, JMS, JBI, MINA or CXF together with working with pluggable Data Format options. Apache Camel is a small library which has minimal dependencies for easy embedding in any Java application.
    6. Book by Gregor & Bobby!
    7. Message Routing
    8. Message Routing in EIP
    9. Camel Components
    10. Simple Routing
    11. More Simple Routing
    12. Pipeline
    13. Multicast Routing
    14. Some examples of the EIP implemation
    15. Message Filter
    16. 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> from(\"activemq:topic:Quotes). filter().xpath(\"/quote/product = ‘widget’\"). to(\"mqseries:WidgetQuotes\");
    17. Language Support For Message Processing • BeanShell • JSP EL • Javascript • OGNL • Groovy • SQL • Python • Xpath • PHP • XQuery • Ruby
    18. Message Filter : Spring XML <?xml version=\"1.0\" encoding=\"UTF-8\"?> <beans xmlns=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd\"> <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> </beans>
    19. Message Filter : Java Complete package com.acme.quotes; import org.apache.camel.builder.RouteBuilder; public class MyRouteBuilder extends RouteBuilder { public void configure() { // forward widget quotes to MQSeries from(\"activemq:topic:Quotes). filter().xpath(\"/quote/product = ‘widget’\"). to(\"mqseries:WidgetQuotes\"); } }
    20. Starting the CamelContext CamelContext context = new DefaultCamelContext(); context.addRoutes(new MyRouteBuilder()); context.start(); <camelContext id=\"camel\" xmlns=\"http://activemq.apache.org/camel/schema/spring\"> <route> <from uri=\"direct:start\"/> <choice> <when> <xpath>$destination = 'firstChoice'</xpath> <to uri=\"mock:matched\"/> </when> <otherwise> <to uri=\"mock:notMatched\"/> </otherwise> </choice> </route> </camelContext>
    21. Content Base Router from(\"activemq:NewOrders”). choice().when(\"/quote/product = ‘widget’\"). to(\"activemq:Orders.Widgets\"). choice().when(\"/quote/product = ‘gadget’\"). to(\"activemq:Orders.Gadgets\"). otherwise().to(\"activemq:Orders.Bad\");
    22. 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>
    23. How camel do this routing work ? •Camel Components •Camel Endpoints •Camel Consumer •Camel Producer •Camel-Core
    24. How camel do this routing work ? http://activemq.apache.org/camel/architecture.html
    25. Beans
    26. Bean as a Message Translator from(\"activemq:Incoming”). beanRef(\"myBeanName\"). to(\"activemq:Outgoing\");
    27. Bean public class Foo { public void someMethod(String name) { ... } }
    28. Bean as a Message Translator with method name from(\"activemq:Incoming”). beanRef(\"myBeanName\", \"someMethod\"). to(\"activemq:Outgoing\");
    29. Binding Beans to Camel Endpoints public class Foo { @MessageDriven(uri=\"activemq:cheese\") public void onCheese(String name) { ... } }
    30. Binding Method Arguments public class Foo { public void onCheese( @XPath(\"/foo/bar\") String name, @Header(\"JMSCorrelationID\") String id) { ... } } for more annotations see http://activemq.apache.org/camel/bean-integration.html
    31. Type Conversion
    32. Type Conversion package com.acme.foo.converters; import org.apache.camel.Converter; import java.io.*; @Converter public class IOConverter { @Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream(new FileInputStream(file)); } } # META-INF/services/org/apache/camel/TypeConverter com.acme.foo.converters
    33. Type Conversion protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from(\"direct:start\").convertBodyTo(InputStream.class).to(\"mock:result\"); } }; } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from(\"direct:start\").process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(InputStream.class)); } }).to(\"mock:result\"); }; }
    34. Data Format from(\"activemq:QueueWithJavaObjects). marshal().jaxb(). to(\"mqseries:QueueWithXmlMessages\"); from(\"activemq:QueueWithXmlMessages). unmarshal().jaxb(). to(\"mqseries:QueueWithJavaObjects\"); from(\"activemq:QueueTestMessage). marshal().zip(). to(\"mqseries:QueueWithCompressMessage\");
    35. Riding tips of camel
    36. Camel Riding from Java •/META-INF/spring/camelContext.xml •set the CLASSPATH •java org.apache.camel.spring.Main
    37. Maven Tooling <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> mvn camel:run
    38. Maven Plugin Site Report
    39. Writing You Own Component •Component •Endpoint •Consumer •Provider
    40. Where would I use Camel? •standalone or in any Spring application •inside ActiveMQ’s JMS client or the broker •inside your ESB such as ServiceMix via the servicemix-camel Service Unit •inside CXF either as a transport or reusing CXF inside Camel
    41. How to write your routing rule in Camel •What's the magic of from, to, choice ...... • /camel-core/src/main/java/org/apache/camel/model •Implementing it in DSL way • Defining the type class that you want •Implementing it in a Spring configuration way • Adding the annotation for JAXB consuming
    42. Questions?
    43. Let's take a look at Camel-CXF example •Open eclipse and go to code please •What does Camel-CXF example have ? •Multi-binding and Multi-transport supporting •LoadBalancing •JAXWS WebSerivce Provider API
    44. Where do I get more info? please do take Camel for a ride! http://activemq.apache.org/camel/ don’t get the hump! :-)

    + Apache Event BeijingApache Event Beijing, 11 months ago

    custom

    1766 views, 2 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1766
      • 1766 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 30
    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