Solving Enterprise Integration
With
Apache Camel
Christian Posta
Principal Consultant and Architect

11/09/13
1
Agenda
• 
• 
• 
• 
• 

2

What is Integration?
What is Apache Camel
Why Apache Camel?
Example
Questions?
Your speaker
Christian Posta
Blog: http://christianposta.com/blog
Twitter: @christianposta
Email: christian@redhat.com
ceposta@apache.org

•  Principal Consultant and Architect at Red Hat (FuseSource)
•  Based in Phoenix, AZ
•  Committer on Apache Camel, ActiveMQ, Apollo
•  PMC on ActiveMQ
•  Author: Essential Camel Components DZone Refcard
3
What is Integration?

4

4
Integration?

5
Integration…

6
Just use one computer.
No integration needed.

7
Why is integration hard?
•  Off the shelf? Home Grown? Acquisition?
•  Platforms
•  Protocols / Data Formats
•  Data Formats
•  Timing
•  Organizational mismatch

8
Commercial Solutions?

9
Enterprise Service Bus?

10
Enterprise Service Bus…

11
Extract the heart of ESB
•  Protocol mediation
•  Routing
•  Transformation
•  EIPs
•  Start small, build up
•  Open Source
•  Community driven

12
Patterns FTW!
•  Common language!!!!!
•  Specific context
•  Forces at work
•  Concrete solution
•  Guidance
•  Other patterns…
•  65 patterns

13
What is Apache Camel?

14
14
Proud parents of Camel

15
Apache Camel
Apache Camel is an open-source,
light-weight, integration library.

Use Camel to integrate disparate systems
that speak different protocols and data formats
16
Why the name Camel?
•  Can carry more weight that other
beasts?

•  James fancied the cigarettes?
•  A horse designed by committee?
17

Concise
Application
Messaging
Exchange
Language
What is Apache Camel?
•  Light-weight integration library
•  Enterprise Integration Patterns
•  Components
•  Domain Specific Language
•  Routing and Mediation (like an ESB?)
•  Runs in any container (or stand alone)

18
Not an ESB…per-se…
•  An integration library
• 
• 
• 

Routing (content-based, dynamic, rules-engine…)
Mediation (xformations, protocols, wire transports…)
DSL

•  Can build an ESB (real ESB.. Not just box in the
middle)
•  Many options based on Camel!
• 
• 
• 
• 
19

Fuse ESB / JBoss Fuse
Apache ServiceMix (Karaf + Camel)
Talend, wso2, others…
Not tied to vendor lock-in and commercial licenses!
Quick Example

20
20
Quick Example

File System

21

Message Oriented Middleware
Quick Example

From A

22

Filter
message

Send to B
Quick Example

from(A)

23

filter(predicate)

to(B)
Quick Example

from(A)

24

.filter(isWidget)

.to(B)
Quick Example

isWidget = xpath(“/quote/product = ‘widget’”);
from(A) .filter(isWidget). to(B)

25
Using Camel

26
26
Very popular
•  Used at top companies in finance, shipping,
retail/e-retail, health care, airline
reservations, etc

•  FAA: http://fusesource.com/collateral/131
•  Sabre: http://fusesource.com/collateral/139
•  CERN: http://fusesource.com/collateral/103
27
Open source
•  Apache Software Foundation
•  ASL v 2.0 Licensed
•  Vibrant community
• 

• 

28

Jira, mailing list, github

Lots of contributions! Check out the components!
Pipes and Filters

•  Step by Step – “Processors” in Camel terminology
•  Complex processing – “Routes”
•  Flexible
•  Testing
•  Reuse

29
Camel Routes
•  Defined in Java, XML, Scala, Groovy
•  Step by step processing of a message:
•  Consumer – Listen for incoming message
•  Zero or more “filters” or Processors
•  Producer – Send outgoing message
•  Number of processing filters, or “Processors” in
Camel-speak
•  EIPs
•  Tranform, redirect, enrich
30
Domain Specific Language
•  Domain specific (integration)
•  Used to build and describe Camel Routes
•  Embedded within a general programming language
•  Java, Spring XML, Scala, Groovy
•  Take advantage of existing tools
•  Fluent builders (builder pattern…)
• 

31

from(“..”).enrich(“…”).filter(“..”).to(“…”);
Java DSL
public class OrderProcessorRouteBuilder extends RouteBuilder {	
	
@Override	
public void configure() throws Exception {	
	
from(“activemq:orders”)	
	.choice()	
.when(header(“customer-rating”).isEqualTo(“gold”))	
.to(“ibmmq:topic:specialCustomer”)	
.otherwise()	
.to(“ftp://user@host/orders/regularCustomers”)	
.end()	
.log(“received new order ${body.orderId}”)	
.to(“ibatis:storeOrder?statementType=Insert”);	
}	
}	
32
Spring XML DSL
<route id=“processOrders”>
<from uri=“activemq:orders”/>
<choice>
<when>
<simple>${header.customer-rating} == ‘gold’</simple>
<to uri=“ibmmq:topic:specialCustomer”>
</when>
<otherwise>
<to uri=“ftp://user@host/orders/regularCustomers” />
</otherwise>
</choice>
<log message=“received new order ${body.orderId}”/>
<to uri=“ibatis:storeOrder?statementType=Insert”/>
</route>	
33
Enterprise Integration Patterns
•  Message Routing
•  Transformation
•  Aggregation
•  Splitting
•  Resequencer
•  Routing Slip
•  Enricher
•  All from the book!
34
Components
•  Prepackaged bits of code
•  Highly configurable
•  Maximum interoperability
•  Used to build “Adapters” to existing systems
•  Don’t reinvent the wheel and end up with a box

35
Components
http://camel.apache.org/components.html
•  ActiveMQ, Websphere, Weblogic (JMS)
•  AMQP

•  HTTP

•  ATOM feeds

•  IRC

•  AWS (S3, SQS, SNS, others)

•  jclouds

•  Bean

•  JDBC

•  Cache (EHCache)

•  Jetty

•  CXF (JAX-WS, JAX-RS)

•  Twitter

•  EJB

•  MQTT

•  Drools

•  MyBatis

•  File

•  JPA

•  FTP

•  Spring Integration

•  Google App Engine

36

•  GMail

•  Spring Web Services

To see list of all
components!!
Components
•  URI format:
• 

scheme:localPart[?options]

• 

scheme: identifies the “component”

• 

localPart: specific to the component

• 

options: is a list of name-value pairs

•  Creates endpoints based on configuration
•  Route endpoint “factories”
•  Integrate with Camel Routes by creating producer/
consumer endpoints
37
Another Example
public class MyExampleRouteBuilder extends RouteBuilder {	
	
@Override	
public void configure() throws Exception {	
	
from(“aws-sqs://demo?defaultVisibilityTimeout=2”)	
	
	

}	

}	

38

	.setHeader(“type”).jsonpath(“$[‘type’]”)	
	.filter(simple(“${header.type} == ‘login’”)

	

	.to(“jms:quote”);
Test Framework
•  Powerful way to test your Camel routes
• 

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

•  Uses Mocks
•  Mocks vs Stubs?
• 

http://martinfowler.com/articles/mocksArentStubs.html

•  Provides declarative testing mechanism
•  Declare
•  Test
•  Assert

39
Management with HawtIO
http://hawt.io

40
Developer Tooling Support
Fuse IDE

41
JBoss Fuse (aka Fuse ESB)

42
JBoss Fuse (aka Fuse ESB)

43
Live Demo
can be found here:
https://github.com/christian-posta/camel-sqs-example

44
44
Resources

45
45
Dzone Refcardz
REFCARDZ

•  Camel Essential Components
• 

http://refcardz.dzone.com/refcardz/essential-camel-components

•  Essential EIP with Apache Camel
• 

http://refcardz.dzone.com/refcardz/enterprise-integration

46
Apache Community
•  http://camel.apache.org
•  Mailing list: users@camel.apache.org
•  Nabble Archive:

http://camel.465427.n5.nabble.com/Camel-Users-f465428.html

•  Source code: http://svn.apache.org/viewvc/camel/trunk/
•  Blogs, Articles, Examples
• 

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

• 

http://camel.apache.org/user-stories.html

• 

http://camel.apache.org/user-stories.html

• 

http://www.davsclaus.com

• 

http://www.christianposta.com/blog

47
Apache Camel Books

48
Apache Camel Books

49
Questions
50

Solving Enterprise Integration with Apache Camel

  • 1.
    Solving Enterprise Integration With ApacheCamel Christian Posta Principal Consultant and Architect 11/09/13 1
  • 2.
    Agenda •  •  •  •  •  2 What is Integration? Whatis Apache Camel Why Apache Camel? Example Questions?
  • 3.
    Your speaker Christian Posta Blog:http://christianposta.com/blog Twitter: @christianposta Email: christian@redhat.com ceposta@apache.org •  Principal Consultant and Architect at Red Hat (FuseSource) •  Based in Phoenix, AZ •  Committer on Apache Camel, ActiveMQ, Apollo •  PMC on ActiveMQ •  Author: Essential Camel Components DZone Refcard 3
  • 4.
  • 5.
  • 6.
  • 7.
    Just use onecomputer. No integration needed. 7
  • 8.
    Why is integrationhard? •  Off the shelf? Home Grown? Acquisition? •  Platforms •  Protocols / Data Formats •  Data Formats •  Timing •  Organizational mismatch 8
  • 9.
  • 10.
  • 11.
  • 12.
    Extract the heartof ESB •  Protocol mediation •  Routing •  Transformation •  EIPs •  Start small, build up •  Open Source •  Community driven 12
  • 13.
    Patterns FTW! •  Commonlanguage!!!!! •  Specific context •  Forces at work •  Concrete solution •  Guidance •  Other patterns… •  65 patterns 13
  • 14.
    What is ApacheCamel? 14 14
  • 15.
  • 16.
    Apache Camel Apache Camelis an open-source, light-weight, integration library. Use Camel to integrate disparate systems that speak different protocols and data formats 16
  • 17.
    Why the nameCamel? •  Can carry more weight that other beasts? •  James fancied the cigarettes? •  A horse designed by committee? 17 Concise Application Messaging Exchange Language
  • 18.
    What is ApacheCamel? •  Light-weight integration library •  Enterprise Integration Patterns •  Components •  Domain Specific Language •  Routing and Mediation (like an ESB?) •  Runs in any container (or stand alone) 18
  • 19.
    Not an ESB…per-se… • An integration library •  •  •  Routing (content-based, dynamic, rules-engine…) Mediation (xformations, protocols, wire transports…) DSL •  Can build an ESB (real ESB.. Not just box in the middle) •  Many options based on Camel! •  •  •  •  19 Fuse ESB / JBoss Fuse Apache ServiceMix (Karaf + Camel) Talend, wso2, others… Not tied to vendor lock-in and commercial licenses!
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
    Quick Example isWidget =xpath(“/quote/product = ‘widget’”); from(A) .filter(isWidget). to(B) 25
  • 26.
  • 27.
    Very popular •  Usedat top companies in finance, shipping, retail/e-retail, health care, airline reservations, etc •  FAA: http://fusesource.com/collateral/131 •  Sabre: http://fusesource.com/collateral/139 •  CERN: http://fusesource.com/collateral/103 27
  • 28.
    Open source •  ApacheSoftware Foundation •  ASL v 2.0 Licensed •  Vibrant community •  •  28 Jira, mailing list, github Lots of contributions! Check out the components!
  • 29.
    Pipes and Filters • Step by Step – “Processors” in Camel terminology •  Complex processing – “Routes” •  Flexible •  Testing •  Reuse 29
  • 30.
    Camel Routes •  Definedin Java, XML, Scala, Groovy •  Step by step processing of a message: •  Consumer – Listen for incoming message •  Zero or more “filters” or Processors •  Producer – Send outgoing message •  Number of processing filters, or “Processors” in Camel-speak •  EIPs •  Tranform, redirect, enrich 30
  • 31.
    Domain Specific Language • Domain specific (integration) •  Used to build and describe Camel Routes •  Embedded within a general programming language •  Java, Spring XML, Scala, Groovy •  Take advantage of existing tools •  Fluent builders (builder pattern…) •  31 from(“..”).enrich(“…”).filter(“..”).to(“…”);
  • 32.
    Java DSL public classOrderProcessorRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from(“activemq:orders”) .choice() .when(header(“customer-rating”).isEqualTo(“gold”)) .to(“ibmmq:topic:specialCustomer”) .otherwise() .to(“ftp://user@host/orders/regularCustomers”) .end() .log(“received new order ${body.orderId}”) .to(“ibatis:storeOrder?statementType=Insert”); } } 32
  • 33.
    Spring XML DSL <routeid=“processOrders”> <from uri=“activemq:orders”/> <choice> <when> <simple>${header.customer-rating} == ‘gold’</simple> <to uri=“ibmmq:topic:specialCustomer”> </when> <otherwise> <to uri=“ftp://user@host/orders/regularCustomers” /> </otherwise> </choice> <log message=“received new order ${body.orderId}”/> <to uri=“ibatis:storeOrder?statementType=Insert”/> </route> 33
  • 34.
    Enterprise Integration Patterns • Message Routing •  Transformation •  Aggregation •  Splitting •  Resequencer •  Routing Slip •  Enricher •  All from the book! 34
  • 35.
    Components •  Prepackaged bitsof code •  Highly configurable •  Maximum interoperability •  Used to build “Adapters” to existing systems •  Don’t reinvent the wheel and end up with a box 35
  • 36.
    Components http://camel.apache.org/components.html •  ActiveMQ, Websphere,Weblogic (JMS) •  AMQP •  HTTP •  ATOM feeds •  IRC •  AWS (S3, SQS, SNS, others) •  jclouds •  Bean •  JDBC •  Cache (EHCache) •  Jetty •  CXF (JAX-WS, JAX-RS) •  Twitter •  EJB •  MQTT •  Drools •  MyBatis •  File •  JPA •  FTP •  Spring Integration •  Google App Engine 36 •  GMail •  Spring Web Services To see list of all components!!
  • 37.
    Components •  URI format: •  scheme:localPart[?options] •  scheme:identifies the “component” •  localPart: specific to the component •  options: is a list of name-value pairs •  Creates endpoints based on configuration •  Route endpoint “factories” •  Integrate with Camel Routes by creating producer/ consumer endpoints 37
  • 38.
    Another Example public classMyExampleRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from(“aws-sqs://demo?defaultVisibilityTimeout=2”) } } 38 .setHeader(“type”).jsonpath(“$[‘type’]”) .filter(simple(“${header.type} == ‘login’”) .to(“jms:quote”);
  • 39.
    Test Framework •  Powerfulway to test your Camel routes •  http://camel.apache.org/mock.html •  Uses Mocks •  Mocks vs Stubs? •  http://martinfowler.com/articles/mocksArentStubs.html •  Provides declarative testing mechanism •  Declare •  Test •  Assert 39
  • 40.
  • 41.
  • 42.
    JBoss Fuse (akaFuse ESB) 42
  • 43.
    JBoss Fuse (akaFuse ESB) 43
  • 44.
    Live Demo can befound here: https://github.com/christian-posta/camel-sqs-example 44 44
  • 45.
  • 46.
    Dzone Refcardz REFCARDZ •  CamelEssential Components •  http://refcardz.dzone.com/refcardz/essential-camel-components •  Essential EIP with Apache Camel •  http://refcardz.dzone.com/refcardz/enterprise-integration 46
  • 47.
    Apache Community •  http://camel.apache.org • Mailing list: users@camel.apache.org •  Nabble Archive: http://camel.465427.n5.nabble.com/Camel-Users-f465428.html •  Source code: http://svn.apache.org/viewvc/camel/trunk/ •  Blogs, Articles, Examples •  http://camel.apache.org/articles.html •  http://camel.apache.org/user-stories.html •  http://camel.apache.org/user-stories.html •  http://www.davsclaus.com •  http://www.christianposta.com/blog 47
  • 48.
  • 49.
  • 50.