DOSUG Taking Apache Camel For A Ride

50 %
50 %
Information about DOSUG Taking Apache Camel For A Ride

Published on June 13, 2008

Author: programr

Source: slideshare.net

Description

Bruce Snyder's excellent talk on Apache Camel to the Denver Open Source Users Group (www.denveropensource.org) in June 2008

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=quot;http://activemq.apache.org/camel/schema/springquot;> <package>com.acme.quotes</package> </camelContext> 13

Pattern Examples 14

Patterns Again 15

Content Based Router RouteBuilder builder = new RouteBuilder() { public void configure() { from(quot;seda:aquot;).choice().when(header(quot;fooquot;) .isEqualTo(quot;barquot;)).to(quot;seda:bquot;) .when(header(quot;fooquot;).isEqualTo(quot;cheesequot;)) .to(quot;seda:cquot;).otherwise().to(quot;seda:dquot;); } }; 16

Content Based Router <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <route> <from uri=quot;activemq:NewOrdersquot;/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri=quot;activemq:Orders.Widgetsquot;/> </when> <when> <xpath>/order/product = 'gadget'</xpath> <to uri=quot;activemq:Orders.Gadgetsquot;/> </when> <otherwise> <to uri=quot;activemq:Orders.Badquot;/> </otherwise> </choice> </route> </camelContext> 17

Message Filter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:topic:Quotes). filter().xpath(quot;/quote/product = ‘widget’quot;). to(quot;mqseries:WidgetQuotesquot;); } } 18

Message Filter <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <route> <from uri=quot;activemq:topic:Quotesquot;/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to uri=quot;mqseries:WidgetQuotesquot;/> </filter> </route> </camelContext> 19

Splitter public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://ordersquot;). splitter(body().tokenize(quot;nquot;)). to(quot;activemq:Order.Itemsquot;); } } 20

Splitter Using XQuery public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://ordersquot;). splitter().xquery(quot;/order/itemsquot;). to(quot;activemq:Order.Itemsquot;); } } 21

Aggregator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Inventory.Itemsquot;). aggregator().xpath(quot;/order/@idquot;). to(quot;activemq:Inventory.Orderquot;); } } 22

Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;file://incoming”). to(quot;xslt:com/acme/mytransform.xslquot;). to(quot;http://outgoing.com/fooquot;); } } 23

Resequencer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;direct:a”). resequencer(header(quot;JMSPriorityquot;)). to(quot;seda:bquot;); } } 24

Throttler public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). throttler(3).timePeriodMillis(30000). to(quot;seda:bquot;); } } 25

Delayer public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). delayer(header(quot;JMSTimestampquot;, 3000). to(quot;seda:bquot;); } } 26

Combine Patterns public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;seda:a”). resequencer(header(quot;JMSPriorityquot;)). delayer(3000). to(quot;seda:bquot;); } } 27

Beans 28

Bean package com.mycompany.beans; public class MyBean { public void someMethod(String name) { ... } } <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <package>com.mycompany.beans</package> </camelContext> 29

Bean as a Message Translator public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Incoming”). beanRef(quot;myBeanquot;). to(quot;activemq:Outgoingquot;); } } 30

Bean as a Message Translator *With Method Name public class MyRouteBuilder extends RouteBuilder { public void configure() { from(quot;activemq:Incoming”). beanRef(quot;myBeanquot;, quot;someMethodquot;). to(quot;activemq:Outgoingquot;); } } 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=quot;activemq:cheesequot;) public void onCheese(String name) { ... } } 34

Binding Method Arguments public class Foo { public void onCheese( @XPath(quot;/foo/barquot;) String name, @Header(quot;JMSCorrelationIDquot;) String id) { ... } } http://activemq.apache.org/camel/bean-integration.html 35

Injecting Endpoints Into Beans public class Foo { @EndpointInject(uri=quot;activemq:foo.barquot;) ProducerTemplate producer; public void doSomething() { if (whatever) { producer.sendBody(quot;<hello>world!</hello>quot;); } } } 36

Spring Remoting - Server Side <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <export id=quot;sayServicequot; uri=quot;activemq:MyServicequot; serviceRef=quot;sayImplquot; serviceInterface=quot;com.acme.MyServiceInterfacequot;/> </camelContext> <bean id=quot;sayImplquot; class=quot;com.acme.MyServiceImplquot;/> 37

Spring Remoting - Client Side <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> <proxy id=quot;sayServicequot; serviceUrl=quot;activemq:MyServicequot; serviceInterface=quot;com.acme.MyServiceInterfacequot;/> </camelContext> 38

Dependency Injection <camelContext xmlns=quot;http://activemq.apache.org/camel/schema/springquot;> ... </camelContext> <bean id=quot;activemqquot; class=quot;org.apache.camel.component.jms.JmsComponentquot;> <property name=quot;connectionFactoryquot;> <bean class=quot;org.apache.activemq.ActiveMQConnectionFactoryquot;> <property name=quot;brokerURLquot; value=quot;vm://localhost?broker.persistent=falsequot;/> </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(quot;activemq:PurchaseOrdersquot;) .correlate(xpath(quot;/purchaseOrder/@idquot;).stringResult()); ActivityBuilder invoice = activity(quot;activemq:Invoicesquot;) .correlate(xpath(quot;/invoice/@purchaseOrderIdquot;).stringResult()); // now lets add some BAM rules invoice.starts().after(purchaseOrder.completes()) .expectWithin(seconds(1)) .errorIfOver(seconds(2)).to(quot;activemq:FailedProcessesquot;); } } 41

Ride the Camel! 42

Questions? 43

Add a comment

Related pages

Taking Apache Camel For a Ride - Software Summit

Bruce Snyder Ñ Taking Apache Camel for a Ride Slide 67. Finally, the Camel Truck! Colorado Software Summit: October 19 Ð 24, 2008 ...
Read more

Taking Apache Camel For A Ride - Docin.com豆丁网-分享 ...

Taking Apache Camel For A Ride. Taking Apache Camel For RideBruce Snyder bsnyder@apache.org Nov2008 New Orleans, Louisiana Protocol Integration is Common ...
Read more

Taking Apache Camel for a Ride with Bruce Snyder - DZone Java

Taking Apache Camel for a Ride with Bruce ... com.acme.routes Read more

Raible Designs | Taking Apache Camel for a Ride with Bruce ...

Taking Apache Camel for a Ride with Bruce Snyder. Camel is a Java API that allows you to do message routing very ... http://activemq.apache.org/camel ...
Read more

Taking Apache Camel For A Ride - Docin.com豆丁网-分享 ...

Taking Apache Camel For A Ride. ... ("activemq:FailedProcesses"); BusinessActivity Monitoring (BAM) 40 Ride Camel!41 Questions? 42 wliming ...
Read more

Kelsey Carter AS Media

DOSUG Taking Apache Camel For A Ride. View more presentations from Matthew McCullough. Posted by
Read more

Apache Camel: Articles

Taking Camel for a ride by Bruce Snyder; JavaZone Conference ... General Articles. Open Source Integration with Apache Camel by Jonathan Anstey;
Read more

Apache Camel: News - home.apache.org

... Apache Camel 2.9.1. ... Download Camel now and enjoy the ride ... He demonstrated that he is both willing and capable of taking responsibilities ...
Read more