Apache Camel - The integration library

109
Apache Camel The Integration Library @davsclaus davsclaus davsclaus.com Claus Ibsen

Transcript of Apache Camel - The integration library

Page 1: Apache Camel - The integration library

Apache Camel The Integration Library

@davsclaus davsclaus

davsclaus.comClaus Ibsen

Page 2: Apache Camel - The integration library

Claus Ibsen• Principal Software Engineer

at Red Hat

• Apache Camel8 years working with Camel

• Author of Camel in Action books

@davsclaus davsclaus

davsclaus.com

Page 3: Apache Camel - The integration library

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

Page 4: Apache Camel - The integration library

What is Apache Camel?• Quote from the website

Apache Camel is a powerful Open Source Integration Framework

based on Enterprise Integration Patterns

Page 5: Apache Camel - The integration library

What is Apache Camel?• Quote from the website

Apache Camel is a powerful Open Source Integration Framework

based on Enterprise Integration Patterns

Page 6: Apache Camel - The integration library

Integration Framework

Page 7: Apache Camel - The integration library

Enterprise Integration Patterns

Page 8: Apache Camel - The integration library

Enterprise Integration Patterns

Page 9: Apache Camel - The integration library

Content Based Router

Page 10: Apache Camel - The integration library

Content Based Router

from newOrder

Page 11: Apache Camel - The integration library

Content Based Router

from newOrder choice

Page 12: Apache Camel - The integration library

Content Based Router

from newOrder choice when isWidget to widget

Page 13: Apache Camel - The integration library

Content Based Router

from newOrder choice when isWidget to widget otherwise to gadget

Page 14: Apache Camel - The integration library

Content Based Router

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

Page 15: Apache Camel - The integration library

Content Based Router

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

Page 16: Apache Camel - The integration library

Content Based Router

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

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

Page 17: Apache Camel - The integration library

Content Based Router

Endpoint newOrder = endpoint("activemq:queue:newOrder");Predicate isWidget = xpath("/order/product = 'widget'");

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

Page 18: Apache Camel - The integration library

Content Based Router

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 19: Apache Camel - The integration library

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

Page 20: Apache Camel - The integration library

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

Page 21: Apache Camel - The integration library

Java DSLimport 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"); }}

Page 22: Apache Camel - The integration library

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 23: Apache Camel - The integration library

Endpoint 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 24: Apache Camel - The integration library

Endpoint 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 25: Apache Camel - The integration library

Just Java Code

Page 26: Apache Camel - The integration library

Just XML

Page 27: Apache Camel - The integration library

Architecture

Page 28: Apache Camel - The integration library

Componentsahc bindy coap docker

ahc-ws blueprint cometd dozerapns boon context dropbox

atmosphere box couchdb eclipseatom cache crypto ejbaws cassandraql csv elasticsearchbam castor cfx elsql

bean-validator cdi cxf-transport eventadminbeanio chunk disruptor exec

beanstalk cmis dns facebook

Page 29: Apache Camel - The integration library

Componentsflatpack google-drive hbase jacksonxml

fop google-mail hdfs jasyptfreemarker gora hdfs2 javaspace

ftp grape http jaxbgae groovy http4 jbpm

ganglia gson ibatis jcloudsgeocoder guava-eventbus ical jcr

git guice infinispan jdbcgithub hawtdb irc jetty8

google-calendar hazelcast jackson jetty9

Page 30: Apache Camel - The integration library

Componentsjgroups jsonpath leveldb mustache

jibx jt400 linkedin mveljing juel lucene mybatisjira jxpath mail nettyjms kafka metrics netty-httpjmx kestrel mina netty4jolt krati mina2 netty4-http

josql kubernetes mongodb ognljpa kura mqtt olingo2jsch ldap msv openshift

Page 31: Apache Camel - The integration library

Componentsoptaplanner rabbitmq scala smpp

paho restlet schematron snpppaxlogging rmi scr soap

pdf routebox script solrpgevent rss servlet spark-restprinter ruby servletlistener spring

protobuf rx shiro spring-batchquartz salesforce sip spring-bootquarz2 sap-netweaver sjms spring-integrationquickfix saxon slack spring-javaconfig

Page 32: Apache Camel - The integration library

Componentsspring-ldap swagger undertow xmlsecurityspring-redis swagger-java univocity xmpp

spring-security syslog urlrewrite xstreamspring-ws tagsoup velocity yammer

sql tarfile vertx zipfilessh test weather zookeeperstax test-blueprint websocket

stomp test-spring xmlbeansstream testng xmljson

stringtemplate twitter xmlrpc

Page 33: Apache Camel - The integration library
Page 34: Apache Camel - The integration library

+

Page 35: Apache Camel - The integration library

+

+

Page 36: Apache Camel - The integration library

+

+

+

Page 37: Apache Camel - The integration library

+

+

+ =

Page 38: Apache Camel - The integration library

Apache Camel 1.0

Page 39: Apache Camel - The integration library

Apache Camel 2.17.3

Page 40: Apache Camel - The integration library

Pop Quizz

How long time between the first

and the latestrelease ?

Page 41: Apache Camel - The integration library

Pop Quizz

9 years

Page 42: Apache Camel - The integration library

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

Page 43: Apache Camel - The integration library

File Copier Example

Page 44: Apache Camel - The integration library

Public Static Void Main

Page 45: Apache Camel - The integration library

Create CamelContext

Page 46: Apache Camel - The integration library

Add RouteBuilder

Page 47: Apache Camel - The integration library

Java DSL

Page 48: Apache Camel - The integration library

Start / Stop

Page 49: Apache Camel - The integration library

Camel Main

Page 50: Apache Camel - The integration library

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

Page 51: Apache Camel - The integration library

Trying Camel• Download Apache Camel 2.17.3

• tar xf apache-camel-2.17.3.tar.gz • cd apache-camel-2.17.3 • cd examples

read readme.md first

Page 52: Apache Camel - The integration library

Beginner Example• camel-example-console

mvn camel:run

Page 53: Apache Camel - The integration library

Run with web console

mvn io.hawt:hawtio-maven-plugin:1.4.65:camel

http://hawt.io/maven

Page 54: Apache Camel - The integration library

Spring Boot Starter

Page 55: Apache Camel - The integration library

WildFly Swarm Generator

Page 56: Apache Camel - The integration library

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• More Information

Page 57: Apache Camel - The integration library

What's in the Camel Box?

Page 58: Apache Camel - The integration library

Enterprise Integration Patterns

http://camel.apache.org/eip

Page 59: Apache Camel - The integration library

Pipes and Filters EIP

from("file:inbox") .pipeline() .to("bean:decrypt") .to("bean:authenticate") .to("bean:de-dup");

Page 60: Apache Camel - The integration library

Pipes and Filters EIP

from("file:inbox") .to("bean:decrypt") .to("bean:authenticate") .to("bean:de-dup");

pipeline is default mode so its nearly always omitted

Page 61: Apache Camel - The integration library

Recipient List

from("restlet:http://localhost:9080 /stocks/{symbol}?restletMethods=post") .recipientList(simple("activemq:queue:${header.symbol}"));

curl -X POST -d "120" "http://localhost:9080/stock/ORCL"

Page 62: Apache Camel - The integration library

Recipient List

from("restlet:http://localhost:9080 /stocks/{symbol}?restletMethods=post") .recipientList(simple("activemq:queue:${header.symbol}"));

curl -X POST -d "120" "http://localhost:9080/stock/ORCL"

Page 63: Apache Camel - The integration library

Recipient List

from("restlet:http://localhost:9080 /stocks/{symbol}?restletMethods=post") .toD("activemq:queue:${header.symbol}"));

much easier now with toD (to dynamic)

curl -X POST -d "120" "http://localhost:9080/stock/ORCL"

Page 64: Apache Camel - The integration library

Recipient List

restConfiguration().component("restlet").port(9080); rest("stocks") .post("{symbol}") .toD("activemq:queue:${header.symbol}"));

and use rest-dsl

curl -X POST -d "120" "http://localhost:9080/stock/ORCL"

Page 65: Apache Camel - The integration library

Splitter

Page 66: Apache Camel - The integration library

Splitter

from("file:inbox")

Page 67: Apache Camel - The integration library

Splitter

from("file:inbox") .split(body().tokenize("\n"))

Page 68: Apache Camel - The integration library

Splitter

from("file:inbox") .split(body().tokenize("\n")) .marshal(customToXml)

Custom Data Format

Page 69: Apache Camel - The integration library

Splitter

from("file:inbox") .split(body().tokenize("\n")) .marshal(customToXml) .to("activemq:line");

Custom Data Format

Page 70: Apache Camel - The integration library

Componentsahc bindy coap docker

ahc-ws blueprint cometd dozerapns boon context dropbox

atmosphere box couchdb eclipseatom cache crypto ejbaws cassandraql csv elasticsearchbam castor cfx elsql

bean-validator cdi cxf-transport eventadminbeanio chunk disruptor exec

beanstalk cmis dns facebook

camel-catalog:component-list | wc -l 218

Page 71: Apache Camel - The integration library

Data Formatsavro flatpack pgp univocity-fixed

barcode gzip protobuf univocity-tsvbase64 hl7 rss xmlBeansbeanio ical secureXML xmjson

bindy-csv jacksonxml serialization xmlrpcbindy-fixed jaxb soapjaxb xstreambindy-kvp jibx string zip

boon json-gson syslog zipfilecastor json-jackson tarfilecrypto json-xstream tidyMarkup

csv mime-multipart univocity-csv

camel-catalog:dataformat-list | wc -l 47

Page 72: Apache Camel - The integration library

Data Format with JAXB• POJO class with @JAXB annotations

Page 73: Apache Camel - The integration library

Data Format with JAXB• marshal (xml -> pojo) • unmarshal (pojo -> xml)

Page 74: Apache Camel - The integration library

Languagesbean header php sql

constant javaScript python terser

el jsonpath ref tokenize

exchangeProperty jxpath ruby xpath

file mvel simple xquery

groovy ognl spel xtokenize

camel-catalog:language-list | wc -l 26

Page 75: Apache Camel - The integration library

Language w/ Simple

Page 76: Apache Camel - The integration library

Language w/ Groovyhere you can do groovy

programming

Page 77: Apache Camel - The integration library

Camel DSLs

• Java DSL

• XML DSL (spring or OSGi blueprint)

• Groovy DSL

• Scala DSL

Groovy and Scalaare not much in use

Page 78: Apache Camel - The integration library

ProducerTemplate• Client API (alike Spring Templates)

Send a message to any Camel endpoint

Page 79: Apache Camel - The integration library

ProducerTemplate• Client API (alike Spring Templates)

FTP serverJava Application

How to upload a file to a FTP server from Java code

Page 80: Apache Camel - The integration library

ProducerTemplate

FTP serverJava Application

Page 81: Apache Camel - The integration library

FluentProducerTemplate

FTP serverJava Application

Page 82: Apache Camel - The integration library

Test Kit

camel-test camel-test-blueprintcamel-test-cdi camel-test-karaf

camel-test-spring camel-testng

Page 83: Apache Camel - The integration library

camel-test

Page 84: Apache Camel - The integration library

camel-test easy to run or debug

Page 85: Apache Camel - The integration library

camel-test1) set expectations

Page 86: Apache Camel - The integration library

camel-test1) set expectations

2) send message(s)

Page 87: Apache Camel - The integration library

camel-test1) set expectations

2) send message(s)

3) assert

Page 88: Apache Camel - The integration library

Management• JMX

Page 89: Apache Camel - The integration library

• Reliable Shutdown

Graceful Shutdown

Route A

Route B

Route C

2

1

3 4

5

6

Startup Shutdown

Stop accept new messages

Complete current inflight messages

Page 90: Apache Camel - The integration library

Camel Commands• Apache Karaf / ServiceMix / JBoss Fuse

Page 91: Apache Camel - The integration library

Camel Commands• Spring Boot

Page 92: Apache Camel - The integration library

Rest DSL

use REST verbs to define services that becomes Camel routes

Page 93: Apache Camel - The integration library

Rest DSL

configure REST and turn on swagger api

Page 94: Apache Camel - The integration library

Rest DSL

cd examples/camel-example-swagger-xml mvn jetty:run

Page 95: Apache Camel - The integration library

Rest DSL

swagger doc as json schema

Page 96: Apache Camel - The integration library

Rest DSL

embedded swagger-ui

Page 97: Apache Camel - The integration library

Error Handling

Page 98: Apache Camel - The integration library

Error Handling

Page 99: Apache Camel - The integration library

Error Handling

Page 100: Apache Camel - The integration library

Error Handling

Page 101: Apache Camel - The integration library

Circuit Breaker• Netflixx Hystrix

New in Camel 2.18

Page 102: Apache Camel - The integration library

Circuit Breaker• Integrates with Hystrix Dashboard

Page 103: Apache Camel - The integration library

Maven Tooling• Archetypes

camel-archetype-java camel-archetype-componentcamel-archetype-spring camel-archetype-api-component

camel-archetype-web camel-archetype-dataformat

camel-archetype-cdi

camel-archetype-spring-boot camel-archetype-scalacamel-archetype-blueprint camel-archetype-groovy

camel-archetype-spring-dm

camel-archetype-scr camel-archetype-java8

New in Camel 2.18

Page 104: Apache Camel - The integration library

Maven Tooling• camel-maven-plugin

mvn camel:run

Page 105: Apache Camel - The integration library

Maven Tooling• fabric8-camel-maven-plugin

mvn fabric8-camel:validate

http://fabric8.io/guide/camelMavenPlugin.html

Validate your Camel uris

from the source

Page 106: Apache Camel - The integration library

All the other stuffType Converter Transactions

Interceptors Security

Thread Management Route Policy

Reactive Asynchronous Non-Blocking Routing Engine

POJO Routing Debugging & Tracing

Page 107: Apache Camel - The integration library

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

Page 108: Apache Camel - The integration library

Running CamelStandalone Web Application

Camel Spring XML JEE Application

Camel Spring Boot Apache Karaf (OSGi)

Camel CDI Wildfly(wildfly-camel)

Camel Guice vert.x (vertx-camel)

Page 109: Apache Camel - The integration library

More Information• My blog

• http://www.davsclaus.com • Apache Camel 3rd party blogs/articles/etc

• http://camel.apache.org/articles • Camel videos

• https://vimeo.com/tag:apachecamel • Best What is Camel article

• https://dzone.com/articles/open-source-integration-apache

@davsclaus davsclaus.com