85
1 1 Introduction to Apache Camel Claus Ibsen Principal Software Engineer, FuseSource September 2010

Apache Camel Introduction

Embed Size (px)

DESCRIPTION

This webinar introduces Apache Camel's large range of components for connectivity and protocol support, and how the 50+ patterns create a powerful toolbox that lets you build integration solutions "Lego style". This webinar will introduce you to the Camel community and why it is so important for any serious open source project to have a thriving community. Speaker: Claus Ibsen - Camel PMC member and top committer

Citation preview

Page 1: Apache Camel Introduction

11

Introduction to Apache Camel

Claus IbsenPrincipal Software Engineer, FuseSource

September 2010

Page 2: Apache Camel Introduction

When you joined today‟s session …

Audio is broadcast from your computer

Submit your questions

via the Chat Window

Contact today‟s Host

via the Chat Window

Page 3: Apache Camel Introduction

3 © 2010 Progress Software Corporation3

Today's speaker - Claus Ibsen

Principal Software Engineer at FuseSource

• Full time Apache Camel hacker

Apache Camel committer

Co-author of Camel in Action book

• Available in late 2010

Contact

[email protected]

• http://davsclaus.blogspot.com/

• http://twitter.com/davsclaus

http://www.manning.com/ibsen

Page 4: Apache Camel Introduction

4 © 2010 Progress Software Corporation4

Why the name Camel?

Camel is easy to remember and type

Page 5: Apache Camel Introduction

5 © 2010 Progress Software Corporation5

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 6: Apache Camel Introduction

6 © 2010 Progress Software Corporation6

The birth of Apache Camel

• Camel’s parents

Page 7: Apache Camel Introduction

7 © 2010 Progress Software Corporation7

The birth of Apache Camel

Initial Commit Log

r519901 | jstrachan | 2007-03-19 11:54:57 +0100

(Mon, 19 Mar 2007) | 1 line

Initial checkin of Camel routing library

Apache Camel 1.0 released June 2007

Apache Camel is 3 years old

Page 8: Apache Camel Introduction

8 © 2010 Progress Software Corporation

The birth of Apache Camel

My initial commit

r640963 | davsclaus | 2008-03-25 21:07:10 +0100

(Tue, 25 Mar 2008) | 1 line

Added unit test for mistyped URI

8

Page 9: Apache Camel Introduction

9 © 2010 Progress Software Corporation9

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 10: Apache Camel Introduction

10 © 2010 Progress Software Corporation

What is Apache Camel

Quote from the web site

10

Apache Camel is a

Powerful Open Source

Integration Framework

based on known

Enterprise Integration Patterns

Page 11: Apache Camel Introduction

11 © 2010 Progress Software Corporation

What is Apache Camel

Why do we need Integration?

• Your apps are build using different tech stacks

• Critical for your business to integrate

Why Integration Framework?

• Framework do the heavy lifting

• Focus on business problem

• Not "reinventing the wheel"

11

Page 12: Apache Camel Introduction

12 © 2010 Progress Software Corporation

What is Apache Camel

What is Enterprise Integration Patterns?

12

Page 13: Apache Camel Introduction

13 © 2010 Progress Software Corporation

What is Apache Camel

What is Enterprise Integration Patterns?

13

Page 14: Apache Camel Introduction

14 © 2010 Progress Software Corporation

What is Apache Camel

What is Enterprise Integration Patterns?

14

Its a book

Page 15: Apache Camel Introduction

15 © 2010 Progress Software Corporation

What is Apache Camel

Lets look at one of the patterns

15

Page 16: Apache Camel Introduction

16 © 2010 Progress Software Corporation

What is Apache Camel

Use Case

16

ActiveMQ WebSphereMQ

Page 17: Apache Camel Introduction

17 © 2010 Progress Software Corporation

What is Apache Camel

Filter Pattern

17

Page 18: Apache Camel Introduction

18 © 2010 Progress Software Corporation

What is Apache Camel

Filter Pattern

18

from

A

send to

B

filter

message

Page 19: Apache Camel Introduction

19 © 2010 Progress Software Corporation

What is Apache Camel

Filter Pattern

19

from(A) to(B)filter(predicate)

Page 20: Apache Camel Introduction

20 © 2010 Progress Software Corporation

What is Apache Camel

Filter Pattern

20

from(A) .to(B).filter(isWidget)

Page 21: Apache Camel Introduction

21 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route

21

from(A).filter(isWidget).to(B);

Page 22: Apache Camel Introduction

22 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route

22

isWidget = xpath(“/quote/product = „widget‟”);

from(A).filter(isWidget).to(B);

Page 23: Apache Camel Introduction

23 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route

23

Endpoint A = endpoint(“activemq:queue:quote”);

Endpoint B = endpoint(“mq:quote”);

Predicate isWidget = xpath(“/quote/product = „widget‟”);

from(A).filter(isWidget).to(B);

Page 24: Apache Camel Introduction

24 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route - Java DSL

24

public void configure() throws Exception {

Endpoint A = endpoint("activemq:queue:quote");

Endpoint B = endpoint("mq:quote");

Predicate isWidget = xpath("/quote/product = „widget‟");

from(A).filter(isWidget).to(B);

}

Page 25: Apache Camel Introduction

25 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route - Java DSL

25

import org.apache.camel.builder.RouteBuilder;

import static org.apache.camel.builder.xml.XPathBuilder.xpath;

public class FilterRoute extends RouteBuilder {

public void configure() throws Exception {

Endpoint A = endpoint("activemq:queue:quote");

Endpoint B = endpoint("mq:quote");

Predicate isWidget = xpath("/quote/product = „widget‟");

from(A).filter(isWidget).to(B);

}

}

Page 26: Apache Camel Introduction

26 © 2010 Progress Software Corporation

What is Apache Camel

Filter Route - Java DSL

26

import org.apache.camel.builder.RouteBuilder;

public class FilterRoute extends RouteBuilder {

public void configure() throws Exception {

from("activemq:queue:quote")

.filter().xpath("/quote/product =„widget‟")

.to("mq:quote");

}

}

Page 27: Apache Camel Introduction

27 © 2010 Progress Software Corporation

What is Apache Camel

IDE Tooling

27

Code

Assistance

JavaDoc

Page 28: Apache Camel Introduction

28 © 2010 Progress Software Corporation

What is Apache Camel

IDE Tooling

28

Code

Assistance

Page 29: Apache Camel Introduction

29 © 2010 Progress Software Corporation

What is Apache Camel

Lets look at the most famous pattern

29

Page 30: Apache Camel Introduction

30 © 2010 Progress Software Corporation

What is Apache Camel

Content Based Router

30

Page 31: Apache Camel Introduction

31 © 2010 Progress Software Corporation

What is Apache Camel

Content Based Router - Spring XML

31

<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 32: Apache Camel Introduction

32 © 2010 Progress Software Corporation

What is Apache Camel

Content Based Router - Java DSL

32

from("activemq:NewOrders")

.choice()

.when().xpath(“/order/product = 'widget'”)

.to(“activemq:Orders.Widget”)

.otherwise()

.to(“acitvemq:Orders.Gadget”);

Page 33: Apache Camel Introduction

33 © 2010 Progress Software Corporation

What is Apache Camel

Summary

• Camel is an integration framework

• Based on Enterprise Integration Patterns

• Routing and mediation

• Easy to use DSL to define routes

• No heavy specification

• No container dependency

• Payload agnostic

• Connectivity to a great wealth of transports

33

Page 34: Apache Camel Introduction

34 © 2010 Progress Software Corporation

What is Apache Camel

Mission Statement

34

Making integration easier and

more accessible to developers

Page 35: Apache Camel Introduction

35 © 2010 Progress Software Corporation35

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 37: Apache Camel Introduction

37 © 2010 Progress Software Corporation37

A little example

Goals using Enterprise Integration Patterns

Goals

• 1) Pickup files from a directory

• 2) Make sure we only pickup 3 files per 30 seconds

• 3) Store into JMS queue

• 4) Listen on JMS queue

• 5) And upload file to FTP server

1 2 3 4 5

Page 38: Apache Camel Introduction

38 © 2010 Progress Software Corporation38

A little example

Goals using Enterprise Integration Patterns

Goals

• 1) Pickup files from a directory

• 2) Make sure we only pickup 3 files per 30 seconds

• 3) Store into JMS queue

• 4) Listen on JMS queue

• 5) And upload file to FTP server

from throttle to from to

Page 39: Apache Camel Introduction

39 © 2010 Progress Software Corporation39

A little example

Camel DSL in XML

<camelContext>

<route>

<from uri="file:camellos/inbox?move=.done"/>

<throttle maximumRequestsPerPeriod="3”

timePeriodMillis="30000”>

<to uri="activemq:queue:camellos"/>

</throttle>

</route>

<route>

<from uri="activemq:queue:camellos"/>

<to uri="ftp://admin:secret@localhost:3333"/>

</route>

</camelContext>

Page 40: Apache Camel Introduction

40 © 2010 Progress Software Corporation40

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 41: Apache Camel Introduction

41 © 2010 Progress Software Corporation

What's included in the box?

Highlights of whats included in Camel

41

Page 42: Apache Camel Introduction

42 © 2010 Progress Software Corporation

What's included in the box?

50+ EIP patterns

42

http://camel.apache.org/enterprise-integration-patterns.html

Page 43: Apache Camel Introduction

43 © 2010 Progress Software Corporation

What's included in the box?

70+ Components

43

activemq crypto flatpack irc ldap

activemq-journal cxf freemarker javaspace mail/imap/pop3

amqp cxfrs ftp/ftps/sftp jbi mina

atom dataset gae jcr mock

bean direct hdfs jdbc msv

bean validation esper hibernate jetty nagios

browse event hl7 jms netty

cache exec http jpa nmr

cometd file ibatis jt/400 printer

http://camel.apache.org/components.html

Page 44: Apache Camel Introduction

44 © 2010 Progress Software Corporation

What's included in the box?

70+ Components

44

properties scalate stream xslt

quartz seda string-template ejb

quickfix servlet test

ref smooks timer

restlet smpp validation

rmi snmp velocity

rnc spring-integration vm

rng spring-security xmpp

rss sql xquery

http://camel.apache.org/components.html

Page 45: Apache Camel Introduction

45 © 2010 Progress Software Corporation

What's included in the box?

18 Data Formats

45

bindy protobuf

castor serialization

csv soap

crypto tidy markup

flatpack xml beans

gzip xml security

hl7 xstream

jaxb zip

json dozer

http://camel.apache.org/data-format.html

Page 46: Apache Camel Introduction

46 © 2010 Progress Software Corporation

What's included in the box?

Data Format

46

from("activemq:QueueWithJavaObjects”)

.marshal().jaxb()

.to("mq:QueueWithXmlMessages");

Page 47: Apache Camel Introduction

47 © 2010 Progress Software Corporation

What's included in the box?

Predicates & Expressions

47

BeanShell PHP

EL Python

Groovy Ruby

JavaScript Simple

JSR 223 SQL

OGNL XPath

MVEL XQuery

http://camel.apache.org/languages.html

Page 48: Apache Camel Introduction

48 © 2010 Progress Software Corporation

What's included in the box?

DSL in 3 programming languages

48

from(A).filter(isWidget).to(B);

from(A) filter(isWidget) --> B

<route>

<from ref="A"/>

<filter>

<xpath>/quote/product = „widget‟</xpath>

<to ref="B"/>

</filter>

</route>

XML

Java

Scala

Page 49: Apache Camel Introduction

49 © 2010 Progress Software Corporation

What's included in the box?

Type Converters

49

INFO DefaultTypeConverter

- Loaded 148 type converters

Page 50: Apache Camel Introduction

50 © 2010 Progress Software Corporation

What's included in the box?

Custom Type Converters

50

# META-INF/services/org/apache/camel/TypeConverter

com.acme.convertersMETA-INF file in the JAR

@Converter

public class MyTypeConverter {

@Converter

public String toString(MyOrder order) {

StringBuilder sb = new StringBuilder();

...

return sb.toString();

}

}

Page 51: Apache Camel Introduction

51 © 2010 Progress Software Corporation

What's included in the box?

Powerful bean integration

• Adapt to your beans

• EIP as @annotations

- @Produce

- @Consume

- @DynamicRouter

- @RecipientList

- @RoutingSlip

51

more to come in future releases ...

Page 52: Apache Camel Introduction

52 © 2010 Progress Software Corporation

What's included in the box?

Bean as Message Translator

52

Page 53: Apache Camel Introduction

53 © 2010 Progress Software Corporation

What's included in the box?

Bean as Message Translator

53

public class Foo {

public String someMethod(String name) {

return “Hello “ + name;

}

}

from("activemq:Incoming”).

beanRef("myBeanName”, “someMethod").

to("activemq:Outgoing");

Page 54: Apache Camel Introduction

54 © 2010 Progress Software Corporation

What's included in the box?

Bean Parameter Binding with XPath

54

public class Foo {

public String processOrder(

String orderAsXml,

@XPath(“/order/@id") String oid,

@Header("JMSCorrelationID") String cid) {

...

}

}

Page 55: Apache Camel Introduction

55 © 2010 Progress Software Corporation

What's included in the box?

Sending message

55

public class Foo {

@Produce(uri = "activemq:foo.bar")

ProducerTemplate producer;

public void doSomething() {

if (whatEver) {

producer.sendBody("Hello World");

}

}

}

Page 56: Apache Camel Introduction

56 © 2010 Progress Software Corporation

What's included in the box?

Receiving message

56

public class Foo {

@Consume(uri = "activemq:cheese")

public void onCheese(String name) {

...

}

}

Page 57: Apache Camel Introduction

57 © 2010 Progress Software Corporation

What's included in the box?

Test Kit

• camel-test.jar

• JUnit based (3.x and 4.x)

• Supports Spring

• Easy to test

• Quick prototyping

57

Page 58: Apache Camel Introduction

58 © 2010 Progress Software Corporation

What's included in the box?

Test Kit from IDE

58

Right Click ->

Run

Debug

extend CamelTestSupport

Inline RouteBuilder

Page 59: Apache Camel Introduction

59 © 2010 Progress Software Corporation

What's included in the box?

Managed

• JMX API

• REST API

59

Page 60: Apache Camel Introduction

60 © 2010 Progress Software Corporation

What's included in the box?

Web console

• REST API

60

Page 61: Apache Camel Introduction

61 © 2010 Progress Software Corporation

What's included in the box?

FuseSource Rider

61

Page 62: Apache Camel Introduction

62 © 2010 Progress Software Corporation

What's included in the box?

Summary

• 50+ EIP patterns

• 70+ Connectivity components

• 15+ Data formats

• 10+ Languages

• DSL in multiple flavors (Java, XML, Scala, Groovy)

• Automatic type conversion

• Strong bean support

• Test Kit

• Management (JMX, REST)

• Web console

62

Page 63: Apache Camel Introduction

63 © 2010 Progress Software Corporation63

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 64: Apache Camel Introduction

64 © 2010 Progress Software Corporation

Running Camel

Riding the Camel

64

Page 65: Apache Camel Introduction

65 © 2010 Progress Software Corporation

Running Camel

Camel is not a server

Camel is lightweight and embeddable

Known Deployment Options

• Standalone Java Application

• Web Application

• J2EE Application

• JBI

• OSGi

• Google App Engine

• Java Web Start

• Spring Application

65

Known Containers

Apache ServiceMix

Apache ActiveMQ

Apache Tomcat

Jetty

JBoss

IBM WebSphere

BEA WebLogic

Oracle OC4j

GAE

... others

Page 66: Apache Camel Introduction

66 © 2010 Progress Software Corporation

Running Camel

Java Application

Spring Application

66

CamelContext context = new DefaultCamelContext();

context.addRoutes(new MyRouteBuilder());

context.start();

<camelContext>

<package>com.acme.quotes</package>

</camelContext>

Page 67: Apache Camel Introduction

67 © 2010 Progress Software Corporation

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

67

Page 69: Apache Camel Introduction

69 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 3 Routes

69

1

Page 70: Apache Camel Introduction

70 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 3 Routes

70

2

1

Page 71: Apache Camel Introduction

71 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 3 Routes

71

32

1

Page 72: Apache Camel Introduction

72 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 1st Route

72

from

to

1

public class Route1 extends RouteBuilder {

public void configure() throws Exception {

from("ftp:[email protected]?password=secret")

.to("activemq:queue:incoming");

}

}

Page 73: Apache Camel Introduction

73 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 2nd Route

73

tofrom

public class Route2 extends RouteBuilder {

public void configure() throws Exception {

from("jetty:http://localhost:8080/orders")

.inOnly("activemq:queue:incoming")

.transform().constant("OK");

}

}

2

Page 74: Apache Camel Introduction

74 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 3rd Route

74

from to

choice

3

route on next slide

Page 75: Apache Camel Introduction

75 © 2010 Progress Software Corporation

Another Example

Rider Auto Parts Example - 3rd Route

75

public class Route3 extends RouteBuilder {

public void configure() throws Exception {

JaxbDataFormat jaxb = new JaxbDataFormat("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().csv()

.beanRef("orderService”, "csvToXml")

.to("activemq:queue:order")

}

}

Page 76: Apache Camel Introduction

76 © 2010 Progress Software Corporation76

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 77: Apache Camel Introduction

77 © 2010 Progress Software Corporation77

The Camel Community

Camel website

• 52% increase (2010 over 2009)

• Average 2200 visits per weekday (2000 - 2500)

High activity on mailing list

Page 78: Apache Camel Introduction

78 © 2010 Progress Software Corporation78

The Camel Community

20 committers

High commit activity

http://markmail.org/

Page 79: Apache Camel Introduction

79 © 2010 Progress Software Corporation

The Camel Community

Books - Bestseller

• Manning top-15 year to date (2010)

79

#10

Page 80: Apache Camel Introduction

80 © 2010 Progress Software Corporation80

The Camel Community

JIRA tickets

Total 3106

Open 136 (4%)

Resolved 2970 (96%)

Bugs 2 (2% open)

Oldest Bug Dec 2009

Sep 6th 2010

Page 81: Apache Camel Introduction

81 © 2010 Progress Software Corporation81

The Camel Community

A lot in each new release

Release Date Tickets

Camel 2.0 Aug 2009 760

Camel 2.1 Dec 2009 303

Camel 2.2 Feb 2010 180

Camel 2.3 May 2010 278

Camel 2.4 July 2010 182

Camel 2.5 Sep 2010 170+

Page 82: Apache Camel Introduction

82 © 2010 Progress Software Corporation82

The Camel Community

3rd party integrating Camel

• Apache ServiceMix

• Apache ActiveMQ

• Apache James

• OpenESB

• Progress Actional Diagnostics

• FuseHQ

• Open eHealth Integration Platform

• Grails Camel Plugin

• Play Framework

• Akka

• Scalate

• JBoss Drools

• JBoss ESB

In Progress

• Smooks

• Doozer

Page 83: Apache Camel Introduction

83 © 2010 Progress Software Corporation83

Agenda

The birth of Apache Camel

What is Apache Camel

A little example

What's included in the box?

Running Camel

Another Example

The Camel Community

Q and A

Page 84: Apache Camel Introduction

84 © 2010 Progress Software Corporation84

Where do I get more information?Camel website: http://camel.apache.org

Camel article: http://architects.dzone.com/articles/apache-camel-integration

FuseSource website: http://fusesource.com

Camel in Action book: http://manning.com/ibsen

Q and A

Page 85: Apache Camel Introduction

85 © 2010 Progress Software Corporation85

Q and A