1 1 Introduction to Apache Camel Claus Ibsen Principal Software Engineer, FuseSource September 2010
Jun 29, 2015
11
Introduction to Apache Camel
Claus IbsenPrincipal Software Engineer, FuseSource
September 2010
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
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
• http://davsclaus.blogspot.com/
• http://twitter.com/davsclaus
http://www.manning.com/ibsen
4 © 2010 Progress Software Corporation4
Why the name Camel?
Camel is easy to remember and type
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
6 © 2010 Progress Software Corporation6
The birth of Apache Camel
• Camel’s parents
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
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
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
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
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
12 © 2010 Progress Software Corporation
What is Apache Camel
What is Enterprise Integration Patterns?
12
13 © 2010 Progress Software Corporation
What is Apache Camel
What is Enterprise Integration Patterns?
13
14 © 2010 Progress Software Corporation
What is Apache Camel
What is Enterprise Integration Patterns?
14
Its a book
15 © 2010 Progress Software Corporation
What is Apache Camel
Lets look at one of the patterns
15
16 © 2010 Progress Software Corporation
What is Apache Camel
Use Case
16
ActiveMQ WebSphereMQ
17 © 2010 Progress Software Corporation
What is Apache Camel
Filter Pattern
17
18 © 2010 Progress Software Corporation
What is Apache Camel
Filter Pattern
18
from
A
send to
B
filter
message
19 © 2010 Progress Software Corporation
What is Apache Camel
Filter Pattern
19
from(A) to(B)filter(predicate)
20 © 2010 Progress Software Corporation
What is Apache Camel
Filter Pattern
20
from(A) .to(B).filter(isWidget)
21 © 2010 Progress Software Corporation
What is Apache Camel
Filter Route
21
from(A).filter(isWidget).to(B);
22 © 2010 Progress Software Corporation
What is Apache Camel
Filter Route
22
isWidget = xpath(“/quote/product = „widget‟”);
from(A).filter(isWidget).to(B);
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);
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);
}
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);
}
}
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");
}
}
27 © 2010 Progress Software Corporation
What is Apache Camel
IDE Tooling
27
Code
Assistance
JavaDoc
28 © 2010 Progress Software Corporation
What is Apache Camel
IDE Tooling
28
Code
Assistance
29 © 2010 Progress Software Corporation
What is Apache Camel
Lets look at the most famous pattern
29
30 © 2010 Progress Software Corporation
What is Apache Camel
Content Based Router
30
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>
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”);
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
34 © 2010 Progress Software Corporation
What is Apache Camel
Mission Statement
34
Making integration easier and
more accessible to developers
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
36 © 2010 Progress Software Corporation36
A little example
Based on community user (Gunnar Hillert)
• http://hillert.blogspot.com/2009/09/camellos-discovering-apache-
camel-ii.html
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
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
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
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>
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
41 © 2010 Progress Software Corporation
What's included in the box?
Highlights of whats included in Camel
41
42 © 2010 Progress Software Corporation
What's included in the box?
50+ EIP patterns
42
http://camel.apache.org/enterprise-integration-patterns.html
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
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
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
46 © 2010 Progress Software Corporation
What's included in the box?
Data Format
46
from("activemq:QueueWithJavaObjects”)
.marshal().jaxb()
.to("mq:QueueWithXmlMessages");
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
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
49 © 2010 Progress Software Corporation
What's included in the box?
Type Converters
49
INFO DefaultTypeConverter
- Loaded 148 type converters
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();
}
}
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 ...
52 © 2010 Progress Software Corporation
What's included in the box?
Bean as Message Translator
52
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");
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) {
...
}
}
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");
}
}
}
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) {
...
}
}
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
58 © 2010 Progress Software Corporation
What's included in the box?
Test Kit from IDE
58
Right Click ->
Run
Debug
extend CamelTestSupport
Inline RouteBuilder
59 © 2010 Progress Software Corporation
What's included in the box?
Managed
• JMX API
• REST API
59
60 © 2010 Progress Software Corporation
What's included in the box?
Web console
• REST API
60
61 © 2010 Progress Software Corporation
What's included in the box?
FuseSource Rider
•
61
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
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
64 © 2010 Progress Software Corporation
Running Camel
Riding the Camel
64
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
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>
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
68 © 2010 Progress Software Corporation
Another Example
Rider Auto Parts Example by Jonathan Anstey
68
http://architects.dzone.com/articles/apache-camel-integration
69 © 2010 Progress Software Corporation
Another Example
Rider Auto Parts Example - 3 Routes
69
1
70 © 2010 Progress Software Corporation
Another Example
Rider Auto Parts Example - 3 Routes
70
2
1
71 © 2010 Progress Software Corporation
Another Example
Rider Auto Parts Example - 3 Routes
71
32
1
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");
}
}
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
74 © 2010 Progress Software Corporation
Another Example
Rider Auto Parts Example - 3rd Route
74
from to
choice
3
route on next slide
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")
}
}
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
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
78 © 2010 Progress Software Corporation78
The Camel Community
20 committers
High commit activity
http://markmail.org/
79 © 2010 Progress Software Corporation
The Camel Community
Books - Bestseller
• Manning top-15 year to date (2010)
79
#10
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
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+
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
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
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
85 © 2010 Progress Software Corporation85
Q and A