• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Taking Apache Camel For a Ride
 

Taking Apache Camel For a Ride

on

  • 4,069 views

 

Statistics

Views

Total Views
4,069
Views on SlideShare
4,057
Embed Views
12

Actions

Likes
2
Downloads
63
Comments
0

1 Embed 12

http://www.slideshare.net 12

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Taking Apache Camel For a Ride Taking Apache Camel For a Ride Presentation Transcript

    • Taking Apache Camel For a Ride Bruce Snyder bsnyder@apache.org 3 June 2008 1
    • Integration is Messy! 2
    • System Integration 3
    • Data Formats 4
    • Apache Camel http://activemq.apache.org/camel/ 5
    • What is Apache Camel? 6
    • Enterprise Integration Patterns http://enterpriseintegrationpatterns.com/ 7
    • Patterns 8
    • Message Routing 9
    • Language Support • BeanShell • SQL • Javascript • XPath • Groovy • XQuery • Python • OGNL • PHP • JSR 223 scripting • Ruby 10
    • Apache Camel Components http://activemq.apache.org/camel/components.html 11
    • History of Apache Camel 12
    • 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
    • Pattern Examples 14
    • Patterns Again 15
    • 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
    • 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
    • Message Filter public class MyRouteBuilder extends RouteBuilder { public void configure() { from("activemq:topic:Quotes). filter().xpath("/quote/product = ‘widget’"). to("mqseries:WidgetQuotes"); } } 18
    • 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
    • Splitter public class MyRouteBuilder extends RouteBuilder { public void configure() { from("file://orders"). splitter(body().tokenize("n")). to("activemq:Order.Items"); } } 20
    • Splitter Using XQuery public class MyRouteBuilder extends RouteBuilder { public void configure() { from("file://orders"). splitter().xquery("/order/items"). to("activemq:Order.Items"); } } 21
    • Aggregator public class MyRouteBuilder extends RouteBuilder { public void configure() { from("activemq:Inventory.Items"). aggregator().xpath("/order/@id"). to("activemq:Inventory.Order"); } } 22
    • 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
    • Resequencer public class MyRouteBuilder extends RouteBuilder { public void configure() { from("direct:a”). resequencer(header("JMSPriority")). to("seda:b"); } } 24
    • Throttler public class MyRouteBuilder extends RouteBuilder { public void configure() { from("seda:a”). throttler(3).timePeriodMillis(30000). to("seda:b"); } } 25
    • Delayer public class MyRouteBuilder extends RouteBuilder { public void configure() { from("seda:a”). delayer(header("JMSTimestamp", 3000). to("seda:b"); } } 26
    • Combine Patterns public class MyRouteBuilder extends RouteBuilder { public void configure() { from("seda:a”). resequencer(header("JMSPriority")). delayer(3000). to("seda:b"); } } 27
    • Beans 28
    • 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
    • Bean as a Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from("activemq:Incoming”). beanRef("myBean"). to("activemq:Outgoing"); } } 30
    • 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
    • Type Conversion 32
    • Type Conversion @Converter public class IOConverter { @Converter public static InputStream toInputStream(File file) throws FileNotFoundException { return new BufferedInputStream( new FileInputStream(file)); } } 33
    • Binding Beans to Camel Endpoints public class Foo { @MessageDriven(uri="activemq:cheese") public void onCheese(String name) { ... } } 34
    • 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
    • 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
    • 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
    • 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
    • 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
    • Business Activity Monitoring (BAM) 40
    • 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
    • Ride the Camel! 42
    • Questions? 43