Integration using Apache Camel and Groovy

74
Claus Ibsen Red Hat Integration using Apache Camel & Groovy

description

Apache Camel is versatile integration library that supports a huge number of components, enterprise integration patterns, and programming languages. In this this talk I first introduce you to Apache Camel and its concepts. Then we move on to see how you can use the Groovy programming language with Camel as a first class Groovy DSL to build integration flows. You will also learn how to build a new Camel and Groovy app from scratch from a live demo. And we also touch how you can use Camel from grails using the grails-camel plugin. I will also show the web console tools that give you insight into your running Apache Camel applications, including visual route diagrams with tracing, debugging, and profiling capabilities. This session will be taught with a 50/50 mix of slides and live demos, and it will conclude with Q&A time.

Transcript of Integration using Apache Camel and Groovy

Page 1: Integration using Apache Camel and Groovy

Claus IbsenRed Hat

●Integration usingApache Camel & Groovy

Page 2: Integration using Apache Camel and 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

Page 3: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN3

This awesome ...

Page 4: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN4

These two awesome has ...

Page 5: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN5

These three awesome has ...

Page 6: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN6

These three awesome has something in common

Page 7: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN7

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 8: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN8

Why the name Camel?

Page 9: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN9

Why the name Camel?

Because Camel iseasy to remember and type ...

Page 10: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN10

Why the name Camel?

… or the creator used to smoke cigarets!

http://camel.apache.org/why-the-name-camel.html

Page 11: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN11

What is Apache Camel?

● Quote from the website

Page 12: Integration using Apache Camel and Groovy

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"

Page 13: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN13

What is Apache Camel?

● What is Enterprise Integration Patterns?

It's a book

Page 14: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN14

What is Apache Camel?

● Enterprise Integration Patterns

http://camel.apache.org/eip

Page 15: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN15

What is Apache Camel?

● EIP - Content Based Router

Page 16: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN16

What is Apache Camel?

from newOrder

Page 17: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN17

What is Apache Camel?

from newOrder choice

Page 18: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN18

What is Apache Camel?

from newOrder choice when isWidget to widget

Page 19: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN19

What is Apache Camel?

from newOrder choice when isWidget to widget otherwise to gadget

Page 20: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN20

What is Apache Camel?

from(newOrder) choice when(isWidget) to(widget) otherwise to(gadget)

Page 21: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN21

What is Apache Camel?

from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);

Page 22: Integration using Apache Camel and Groovy

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 :)

Page 23: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN23

What is Apache Camel?

from newOrder choice when isWidget to widget otherwise to gadget

Page 24: Integration using Apache Camel and Groovy

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

Page 25: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN25

What is Apache Camel?

from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget)

We removed that last semi colon ;)

Page 26: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN26

What is Apache Camel?

Endpoint newOrder = endpoint("activemq:queue:newOrder");

from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);

Page 27: Integration using Apache Camel and Groovy

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

Page 28: Integration using Apache Camel and Groovy

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

Page 29: Integration using Apache Camel and Groovy

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(); }

Page 30: Integration using Apache Camel and Groovy

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(); }}

Page 31: Integration using Apache Camel and Groovy

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(); }}

Page 32: Integration using Apache Camel and Groovy

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>

Page 33: Integration using Apache Camel and Groovy

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

Page 34: Integration using Apache Camel and Groovy

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

Page 35: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN35

Standard Java, XML, or Groovy

● Java DSL is just Java

Page 36: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN36

Standard Java, XML, or Groovy

● XML DSL is just XML

● … with XSD schema for validation/tooling

Page 37: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN37

Standard Java, XML, or Groovy

● Groovy DSL is just Groovy

GroovyClosure

Page 38: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN38

What is Apache Camel?

● Camel's Architecture

Page 39: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN39

What is Apache Camel?

150+ Components

Page 40: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN40

What is Apache Camel?

150+ Components

Page 41: Integration using Apache Camel and Groovy

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

Page 42: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN42

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 43: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN43

A Little Example

● File Copier Example

Page 44: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN44

A Little Example

● File Copier Example

Page 45: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN45

A Little Example

● File Copier Example

Page 46: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN46

A Little Example

● File Copier Example

Page 47: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN47

A Little Example

● File Copier Example

Page 48: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN48

A Little Groovy Example

Page 49: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN49

A Little Groovy Example (all source)

Page 50: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN50

A Little Groovy Example

● Run the example● groovy mycamel.groovy

Page 51: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN51

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 52: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN52

Riding Camel

● Downloading Apache Camel● zip/tarball (approx 8mb)

http://camel.apache.org

Page 53: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN53

Riding Camel

● Using Command Shell● Requires: Apache Maven

● From Eclipse

Page 54: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN54

Riding Camel

● Console Example

● cd examples/camel-example-console

● mvn compile exec:java

Page 55: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN55

Riding Camel

● Twitter Example

● cd examples/camel-example-twitter-websocket

● mvn compile exec:java http://localhost:9090/index.html

Page 56: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN56

Riding Camel

● More examples ...

... and further details at website.

http://camel.apache.org/examples

Page 57: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN57

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 58: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN58

Creating new Camel Projects

● Using Command Shell

● .. or from Eclipse

Page 59: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN59

Creating new Camel Projects

● Importing into Eclipse

Existing Maven Project

Page 60: Integration using Apache Camel and Groovy

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

Page 61: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN61

Creating new Camel Projects

● camel-archetype-groovy

mvn installmvn exec:java

Page 62: Integration using Apache Camel and Groovy

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

Page 63: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN63

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 64: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN64

hawtio

● What does it do? ...

Page 65: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN65

hawtio

● Yet another awesome project created by this guy ...

Page 66: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN66

hawtio

Tooling – Web Console - hawtio

http://hawt.io

Page 67: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN67

hawtio

● What does it dofor Apache Camel?

Page 68: Integration using Apache Camel and Groovy

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

Page 69: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN69

Apache Camel & hawtio

Page 70: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN70

Agenda

● What is Apache Camel?

● A little Example

● Riding Camel

● Creating new Camel Projects

● hawtio

● Q & A

Page 71: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN71

These three awesome has something in common

Page 72: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN72

These three awesome has something in common

Page 73: Integration using Apache Camel and Groovy

PUBLIC PRESENTATION | CLAUS IBSEN73

What about a 4th awesome project?

Page 74: Integration using Apache Camel and Groovy

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