Integration using Apache Camel and Groovy
-
Upload
gr8conf -
Category
Technology
-
view
260 -
download
2
description
Transcript of Integration using Apache Camel and Groovy
Claus IbsenRed Hat
●Integration usingApache Camel & Groovy
PUBLIC PRESENTATION | CLAUS IBSEN2
Your Speaker
● Principal Software Engineer at Red Hat
● Apache Camel● 6 years as committer
● Author of Camel in Action book
● Contact● EMail: [email protected]● Twitter: @davsclaus● Blog: http://davsclaus.com● Linkedin: http://www.linkedin.com/in/davsclaus
PUBLIC PRESENTATION | CLAUS IBSEN3
This awesome ...
PUBLIC PRESENTATION | CLAUS IBSEN4
These two awesome has ...
PUBLIC PRESENTATION | CLAUS IBSEN5
These three awesome has ...
PUBLIC PRESENTATION | CLAUS IBSEN6
These three awesome has something in common
PUBLIC PRESENTATION | CLAUS IBSEN7
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN8
Why the name Camel?
PUBLIC PRESENTATION | CLAUS IBSEN9
Why the name Camel?
Because Camel iseasy to remember and type ...
PUBLIC PRESENTATION | CLAUS IBSEN10
Why the name Camel?
… or the creator used to smoke cigarets!
http://camel.apache.org/why-the-name-camel.html
PUBLIC PRESENTATION | CLAUS IBSEN11
What is Apache Camel?
● Quote from the website
PUBLIC PRESENTATION | CLAUS IBSEN12
What is Apache Camel?
● Why do we need integration?● Critical for your business to integrate
● Why Integration Framework?● Framework do the heavy lifting● You can focus on business problem● Not "reinventing the wheel"
PUBLIC PRESENTATION | CLAUS IBSEN13
What is Apache Camel?
● What is Enterprise Integration Patterns?
It's a book
PUBLIC PRESENTATION | CLAUS IBSEN14
What is Apache Camel?
● Enterprise Integration Patterns
http://camel.apache.org/eip
PUBLIC PRESENTATION | CLAUS IBSEN15
What is Apache Camel?
● EIP - Content Based Router
PUBLIC PRESENTATION | CLAUS IBSEN16
What is Apache Camel?
from newOrder
PUBLIC PRESENTATION | CLAUS IBSEN17
What is Apache Camel?
from newOrder choice
PUBLIC PRESENTATION | CLAUS IBSEN18
What is Apache Camel?
from newOrder choice when isWidget to widget
PUBLIC PRESENTATION | CLAUS IBSEN19
What is Apache Camel?
from newOrder choice when isWidget to widget otherwise to gadget
PUBLIC PRESENTATION | CLAUS IBSEN20
What is Apache Camel?
from(newOrder) choice when(isWidget) to(widget) otherwise to(gadget)
PUBLIC PRESENTATION | CLAUS IBSEN21
What is Apache Camel?
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
PUBLIC PRESENTATION | CLAUS IBSEN22
What is Apache Camel?
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);Ups S
orry ...
This is
a gr8conf
so le
ts get G
roovy :)
PUBLIC PRESENTATION | CLAUS IBSEN23
What is Apache Camel?
from newOrder choice when isWidget to widget otherwise to gadget
PUBLIC PRESENTATION | CLAUS IBSEN24
What is Apache Camel?
from newOrder choice when isWidget to widget otherwise to gadgetUnfortu
nately the C
amel
Groovy D
SL is not a
s
awesome …
yet
PUBLIC PRESENTATION | CLAUS IBSEN25
What is Apache Camel?
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget)
We removed that last semi colon ;)
PUBLIC PRESENTATION | CLAUS IBSEN26
What is Apache Camel?
Endpoint newOrder = endpoint("activemq:queue:newOrder");
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
PUBLIC PRESENTATION | CLAUS IBSEN27
What is Apache Camel?
Endpoint newOrder = endpoint("activemq:queue:newOrder");Predicate isWidget = xpath("/order/product = 'widget'");
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
PUBLIC PRESENTATION | CLAUS IBSEN28
What is Apache Camel?
Endpoint newOrder = endpoint("activemq:queue:newOrder");Predicate isWidget = xpath("/order/product = 'widget'");Endpoint widget = endpoint("activemq:queue:widget");Endpoint gadget = endpoint("activemq:queue:gadget");
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
PUBLIC PRESENTATION | CLAUS IBSEN29
What is Apache Camel?
● Java Code
public void configure() throws Exception { Endpoint newOrder = endpoint("activemq:queue:newOrder"); Predicate isWidget = xpath("/order/product = 'widget'"); Endpoint widget = endpoint("activemq:queue:widget"); Endpoint gadget = endpoint("activemq:queue:gadget");
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget) .end(); }
PUBLIC PRESENTATION | CLAUS IBSEN30
What is Apache Camel?
● Java Codeimport org.apache.camel.Endpoint;import org.apache.camel.Predicate;import org.apache.camel.builder.RouteBuilder;
public class MyRoute extends RouteBuilder {
public void configure() throws Exception { Endpoint newOrder = endpoint("activemq:queue:newOrder"); Predicate isWidget = xpath("/order/product = 'widget'"); Endpoint widget = endpoint("activemq:queue:widget"); Endpoint gadget = endpoint("activemq:queue:gadget");
from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget) .end(); }}
PUBLIC PRESENTATION | CLAUS IBSEN31
What is Apache Camel?
● Camel Java DSL
import org.apache.camel.builder.RouteBuilder;
public class MyRoute extends RouteBuilder {
public void configure() throws Exception { from("activemq:queue:newOrder") .choice() .when(xpath("/order/product = 'widget'")) .to("activemq:queue:widget") .otherwise() .to("activemq:queue:gadget") .end(); }}
PUBLIC PRESENTATION | CLAUS IBSEN32
What is Apache Camel?
● Camel XML DSL
<route> <from uri="activemq:queue:newOrder"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri="activemq:queue:widget"/> </when> <otherwise> <to uri="activemq:queue:gadget"/> </otherwise> </choice> </route>
PUBLIC PRESENTATION | CLAUS IBSEN33
What is Apache Camel?
● Endpoint as URIs
<route> <from uri="file:inbox/orders"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri="activemq:queue:widget"/> </when> <otherwise> <to uri="activemq:queue:gadget"/> </otherwise> </choice> </route>
use file instead
PUBLIC PRESENTATION | CLAUS IBSEN34
What is Apache Camel?
● Endpoint as URIs
<route> <from uri="file:inbox/orders?delete=true"/> <choice> <when> <xpath>/order/product = 'widget'</xpath> <to uri="activemq:queue:widget"/> </when> <otherwise> <to uri="activemq:queue:gadget"/> </otherwise> </choice> </route>
parameters
PUBLIC PRESENTATION | CLAUS IBSEN35
Standard Java, XML, or Groovy
● Java DSL is just Java
PUBLIC PRESENTATION | CLAUS IBSEN36
Standard Java, XML, or Groovy
● XML DSL is just XML
● … with XSD schema for validation/tooling
PUBLIC PRESENTATION | CLAUS IBSEN37
Standard Java, XML, or Groovy
● Groovy DSL is just Groovy
GroovyClosure
PUBLIC PRESENTATION | CLAUS IBSEN38
What is Apache Camel?
● Camel's Architecture
PUBLIC PRESENTATION | CLAUS IBSEN39
What is Apache Camel?
150+ Components
PUBLIC PRESENTATION | CLAUS IBSEN40
What is Apache Camel?
150+ Components
PUBLIC PRESENTATION | CLAUS IBSEN41
What is Apache Camel?
● Summary● Integration Framework● Enterprise Integration Patterns (EIP)● Routing (using DSL)● Easy Configuration (endpoint as uri's)● Just Java, XML, or Groovy code● No Container Dependency● A lot of components
PUBLIC PRESENTATION | CLAUS IBSEN42
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN43
A Little Example
● File Copier Example
PUBLIC PRESENTATION | CLAUS IBSEN44
A Little Example
● File Copier Example
PUBLIC PRESENTATION | CLAUS IBSEN45
A Little Example
● File Copier Example
PUBLIC PRESENTATION | CLAUS IBSEN46
A Little Example
● File Copier Example
PUBLIC PRESENTATION | CLAUS IBSEN47
A Little Example
● File Copier Example
PUBLIC PRESENTATION | CLAUS IBSEN48
A Little Groovy Example
PUBLIC PRESENTATION | CLAUS IBSEN49
A Little Groovy Example (all source)
PUBLIC PRESENTATION | CLAUS IBSEN50
A Little Groovy Example
● Run the example● groovy mycamel.groovy
PUBLIC PRESENTATION | CLAUS IBSEN51
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN52
Riding Camel
● Downloading Apache Camel● zip/tarball (approx 8mb)
http://camel.apache.org
PUBLIC PRESENTATION | CLAUS IBSEN53
Riding Camel
● Using Command Shell● Requires: Apache Maven
● From Eclipse
PUBLIC PRESENTATION | CLAUS IBSEN54
Riding Camel
● Console Example
● cd examples/camel-example-console
● mvn compile exec:java
PUBLIC PRESENTATION | CLAUS IBSEN55
Riding Camel
● Twitter Example
● cd examples/camel-example-twitter-websocket
● mvn compile exec:java http://localhost:9090/index.html
PUBLIC PRESENTATION | CLAUS IBSEN56
Riding Camel
● More examples ...
... and further details at website.
http://camel.apache.org/examples
PUBLIC PRESENTATION | CLAUS IBSEN57
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN58
Creating new Camel Projects
● Using Command Shell
● .. or from Eclipse
PUBLIC PRESENTATION | CLAUS IBSEN59
Creating new Camel Projects
● Importing into Eclipse
Existing Maven Project
PUBLIC PRESENTATION | CLAUS IBSEN60
Creating new Camel Projects
● Maven Archetypes
camel-archetype-activemq camel-archetype-java
camel-archetype-blueprint camel-archetype-scala
camel-archetype-component camel-archetype-spring
camel-archetype-dataformat camel-archetype-spring-dm
camel-archetype-groovy camel-archetype-web
PUBLIC PRESENTATION | CLAUS IBSEN61
Creating new Camel Projects
● camel-archetype-groovy
mvn installmvn exec:java
PUBLIC PRESENTATION | CLAUS IBSEN62
Creating new Camel Projects
● camel-archetype-spring
mvn installmvn camel:run
mvn io.hawt:hawtio-maven-plugin:1.4.2:spring
PUBLIC PRESENTATION | CLAUS IBSEN63
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN64
hawtio
● What does it do? ...
PUBLIC PRESENTATION | CLAUS IBSEN65
hawtio
● Yet another awesome project created by this guy ...
PUBLIC PRESENTATION | CLAUS IBSEN66
hawtio
Tooling – Web Console - hawtio
http://hawt.io
PUBLIC PRESENTATION | CLAUS IBSEN67
hawtio
● What does it dofor Apache Camel?
PUBLIC PRESENTATION | CLAUS IBSEN68
hawtio
● Technology Stack● HTML5 single page app● TypeScript → JavaScript● Angular JS● Bootstrap CSS● HTTP/REST ↔ backend● Jolokia on backend for JMX over REST● Plugins expose services as JMX or REST
http://hawt.io/plugins/howPluginsWork.html
PUBLIC PRESENTATION | CLAUS IBSEN69
Apache Camel & hawtio
PUBLIC PRESENTATION | CLAUS IBSEN70
Agenda
● What is Apache Camel?
● A little Example
● Riding Camel
● Creating new Camel Projects
● hawtio
● Q & A
PUBLIC PRESENTATION | CLAUS IBSEN71
These three awesome has something in common
PUBLIC PRESENTATION | CLAUS IBSEN72
These three awesome has something in common
PUBLIC PRESENTATION | CLAUS IBSEN73
What about a 4th awesome project?
PUBLIC PRESENTATION | CLAUS IBSEN74
Any Questions ?
● Contact● EMail: [email protected] / [email protected] ● Twitter: @davsclaus● Blog: http://davsclaus.com● Linkedin: http://www.linkedin.com/in/davsclaus