33
A Progress Software Company Introduction to Apache Camel Bosanac Dejan January 2011

Introduction to Apache Camel

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Introduction to Apache Camel

A Progress Software Company

Introduction toApache Camel

Bosanac DejanJanuary 2011

Page 2: Introduction to Apache Camel

© 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

Page 3: Introduction to Apache Camel

© 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

Page 4: Introduction to Apache Camel

© 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

Page 5: Introduction to Apache Camel

© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company

5

Route example

Content Based Router

Page 6: Introduction to Apache Camel

© 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>

Page 7: Introduction to Apache Camel

© 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”);

Page 8: Introduction to Apache Camel

© 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

Page 9: Introduction to Apache Camel

© 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

Page 10: Introduction to Apache Camel

© 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

Page 11: Introduction to Apache Camel

© 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");

Page 12: Introduction to Apache Camel

© 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

Page 13: Introduction to Apache Camel

© 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

Page 14: Introduction to Apache Camel

© 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

Page 15: Introduction to Apache Camel

© 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

Page 16: Introduction to Apache Camel

© 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

Page 17: Introduction to Apache Camel

© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company

Developer Web Console

17

Page 18: Introduction to Apache Camel

© 2010 FuseSource, a Progress Software Company. All rights reserved. A Progress Software Company

FuseSource Rider

18

Page 19: Introduction to Apache Camel

© 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

Page 20: Introduction to Apache Camel

© 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

Page 21: Introduction to Apache Camel

© 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

Page 22: Introduction to Apache Camel

© 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

Page 23: Introduction to Apache Camel

© 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

Page 24: Introduction to Apache Camel

© 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"); }}

Page 25: Introduction to Apache Camel

© 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"); }}

Page 26: Introduction to Apache Camel

© 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") }}

Page 27: Introduction to Apache Camel

© 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"

Page 28: Introduction to Apache Camel

© 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"); }}

Page 29: Introduction to Apache Camel

© 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 + "]"; }}

Page 30: Introduction to Apache Camel

© 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

Page 31: Introduction to Apache Camel

© 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

Page 32: Introduction to Apache Camel

© 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

Page 33: Introduction to Apache Camel

© 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