Upload
fusesourcecom
View
6.430
Download
7
Embed Size (px)
DESCRIPTION
Citation preview
A Progress Software Company
Introduction toApache Camel
Bosanac DejanJanuary 2011
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
2
About me
Bosanac Dejan Senior Software Engineer at FUSESource - http://
fusesource.com Apache ActiveMQ committer and PMC member Co-author of ActiveMQ in Action
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
3
What is Apache Camel?
Apache Camel is a powerful Open Source Integration
Framework based on known Enterprise Integration Patterns
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
4
Why Apache Camel?
Integration can be messy - variety of protocols and data formats
Framework hides all complexity so you can focus on your business logic
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
5
Route example
Content Based Router
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
6
Content based Router - XML
<camelContext> <route> <from uri="activemq:NewOrders"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri="activemq:Orders.Widgets"/> </when> <otherwise> <to uri="activemq:Orders.Gadgets"/> </otherwise> </choice> </route></camelContext>
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
7
Content Based Router - Java DSL
from("activemq:NewOrders") .choice() .when().xpath(“/order/product = 'widget'”) .to(“activemq:Orders.Widget”) .otherwise() .to(“activemq:Orders.Gadget”);
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
8
50 Enterprise Integration Patterns
http://camel.apache.org/enterprise-integration-patterns.html
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
9
80 Components
activemq cxf flatpack jasypt
activemq-journal cxfrs freemarker javaspace
amqp dataset ftp/ftps/sftp jbi
atom db4o gae jcr
bean direct hdfs jdbc
bean validation ejb hibernate jetty
browse esper hl7 jms
cache event http jmx
cometd exec ibatis jpa
crypto file irc jt/400
http://camel.apache.org/components.html
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
10
80 Components
language properties seda stream
ldap quartz servlet string-template
mail/imap/pop3 quickfix sip test
mina ref smooks timer
mock restlet smpp validation
msv rmi snmp velocity
nagios rnc spring-integration vm
netty rng spring-security xmpp
nmr rss spring-ws xquery
printer scalate sql xslt
http://camel.apache.org/components.html
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
19 Data Formats
11
bindy protobufcastor serialization
csv soapcrypto syslogdozer tidy markup
flatpack xml beansgzip xml securityhl7 xstreamjaxb zipjson
http://camel.apache.org/data-format.html
from("activemq:QueueWithJavaObjects”) .marshal().jaxb() .to("mq:QueueWithXmlMessages");
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
14 Expression Languaes
12
BeanShell PHP
EL Python
Groovy Ruby
JavaScript Simple
JSR 223 SQL
OGNL XPath
MVEL XQuery
http://camel.apache.org/languages.html
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
DSL in 3 programming Languages
13
XML<route> <from ref="A"/> <filter> <xpath>/quote/product = ‘widget’</xpath> <to ref="B"/> </filter></route>
Javafrom(A).filter(isWidget).to(B);
Scalafrom(A) filter(isWidget) --> B
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Running Camel
14
Deployment Strategy• No container dependency• Lightweight• Embeddable
Deployment Options• Standalone• WAR• Spring• J2EE• JBI• OSGi• Cloud
Known ContainersApache ServiceMix
Apache ActiveMQ
Apache Tomcat
Jetty
JBoss
IBM WebSphere
Oracle WebLogic
Oracle OC4j
Glassfish
Google App Engine
... others
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Running Camel
15
CamelContext context = new DefaultCamelContext();context.addRoutes(new MyRouteBuilder());context.start();
<camelContext> <package>com.acme</package></camelContext>
Spring Application
Java Application
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Managing Camel
JMX API REST API
16
Fuse HQ SOA management and monitoring system based on Hyperic HQ Enterprise
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Developer Web Console
17
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
FuseSource Rider
18
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Auto Parts Example by Jonathan Anstey
19
http://architects.dzone.com/articles/apache-camel-integration
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Auto Parts Example by Jonathan Anstey
20
http://architects.dzone.com/articles/apache-camel-integration
1
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Auto Parts Example by Jonathan Anstey
21
http://architects.dzone.com/articles/apache-camel-integration
2
1
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Auto Parts Example by Jonathan Anstey
22
http://architects.dzone.com/articles/apache-camel-integration
1
23
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Spring Configuration
<broker xmlns="http://activemq.apache.org/schema/core" persistent="false"> <transportConnectors> <transportConnectoruri="tcp://localhost:61616" /> </transportConnectors></broker>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="brokerURL" value="tcp://localhost:61616"/></bean>
<bean id="helper" class="org.fusesource.camel.OrderHelper"/>
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring"> <package>org.fusesource.camel</package></camelContext>
23
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Route 1
24
public class Route1 extends RouteBuilder {
public void configure() throws Exception { from("ftp:[email protected]?password=secret") .to("activemq:queue:incoming"); }}
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Route 2
25
public class Route2 extends RouteBuilder {
public void configure() throws Exception { from("jetty:http://localhost:8080/orders") .inOnly("activemq:queue:incoming") .transform().constant("OK"); }}
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Route 3
26
public class Route3 extends RouteBuilder {
public void configure() throws Exception { JaxbDataFormat jaxb = new JaxbDataFormat("com.rider"); BindyDataFormat bindy = new BindyDataFormat("com.rider");
from("activemq:queue:incoming") .convertBodyTo(String.class) .choice() .when().method("helper”, "isXml") .unmarshal(jaxb) .to("activemq:queue:order") .when().method("helper”, "isCsv") .unmarshal(bindy) .to("activemq:queue:order") }}
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Data Samples
27
XML Data
<?xml version="1.0" encoding="UTF-8"?><order name="motor" amount="1"/>
CSV Data
"name", "amount""brake pad", "2"
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Order helper
28
public class OrderHelper { public boolean isCsv(String body) { return !body.contains("<?xml"); } public boolean isXml(String body) { return body.contains("<?xml"); }}
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
Rider Example - Order Bean
29
@XmlAccessorType(XmlAccessType.FIELD)public class Order implements Serializable { @XmlAttribute private String name; @XmlAttribute private int amount; public Order() { } public Order(String name, int amount) { this.name = name; this.amount = amount; } @Override public String toString() { return "Order[" + name + " , " + amount + "]"; }}
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
What else is there?
Error handling EIP annotations Test Kit Transactions Interceptors Security ...
30
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
More Information
31
Where do I get more information? Camel website: http://camel.apache.org Camel article: http://architects.dzone.com/articles/apache-camel-
integration Camel in Action book: http://manning.com/ibsen
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
32
Blog: http://www.nighttale.net/
Twitter: http://twitter.com/dejanbhttp://twitter.com/fusenews
© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company
32
Questions?Blog: http://www.nighttale.net/
Twitter: http://twitter.com/dejanbhttp://twitter.com/fusenews