104
Apache Camel The Integration Library EU 2016 Claus Ibsen

ApacheCon EU 2016 - Apache Camel the integration library

Embed Size (px)

Citation preview

Page 1: ApacheCon EU 2016 - Apache Camel the integration library

Apache CamelThe Integration

Library

EU 2016

Claus Ibsen

Page 2: ApacheCon EU 2016 - Apache Camel the integration library

Claus Ibsen• Senior Principal Software Engineer

at Red Hat

• Apache Camel8+ years commiter and PMC member

• Author ofCamel in Action books

@davsclausdavsclaus

[email protected]

Page 3: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - Apache Camel the integration library

What is Apache Camel?

• Quote from the website

Apache Camel is apowerful Open SourceIntegration Framework

based onEnterprise Integration Patterns

Page 5: ApacheCon EU 2016 - Apache Camel the integration library

What is Apache Camel?

• Quote from the website

Apache Camel is apowerful Open SourceIntegration Framework

based onEnterprise Integration Patterns

Page 6: ApacheCon EU 2016 - Apache Camel the integration library

Integration Framework

Page 7: ApacheCon EU 2016 - Apache Camel the integration library

Enterprise Integration Patterns

Page 8: ApacheCon EU 2016 - Apache Camel the integration library

Enterprise Integration Patterns

Page 9: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

Page 10: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

from newOrder

Page 11: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

from newOrder choice

Page 12: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

from newOrder choice when isWidget to widget

Page 13: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

from newOrder choice when isWidget to widget otherwise to gadget

Page 14: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

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

Page 15: ApacheCon EU 2016 - Apache Camel the integration library

Content Based Router

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

Page 16: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - Apache Camel the integration library

Just Java Code

Page 26: ApacheCon EU 2016 - Apache Camel the integration library

Just XML

Page 27: ApacheCon EU 2016 - Apache Camel the integration library

Architecture

Page 28: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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 jclouds

geocoder guava-eventbus ical jcr

git guice infinispan jdbcgithub hawtdb irc jetty8google-calendar hazelcast jackson jetty9

Page 30: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - 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-boot

quarz2 sap-netweaver sjms spring-integration

quickfix saxon slack spring-javaconfig

Page 32: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - Apache Camel the integration library
Page 34: ApacheCon EU 2016 - Apache Camel the integration library

+

Page 35: ApacheCon EU 2016 - Apache Camel the integration library

+

+

Page 36: ApacheCon EU 2016 - Apache Camel the integration library

+

+

+

Page 37: ApacheCon EU 2016 - Apache Camel the integration library

+

+

+ =

Page 38: ApacheCon EU 2016 - Apache Camel the integration library

Apache Camelon GitHub Numbers

• Project created March 2007

• 1058 Stars

• 102 Releases

• 25000+ Commits

• 253 Contributors

• 1254 Closed Pull Requests

A star on github is appreciated

Page 39: ApacheCon EU 2016 - 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 40: ApacheCon EU 2016 - Apache Camel the integration library

File Copier Example

Page 41: ApacheCon EU 2016 - Apache Camel the integration library

Public Static Void Main

Page 42: ApacheCon EU 2016 - Apache Camel the integration library

Create CamelContext

Page 43: ApacheCon EU 2016 - Apache Camel the integration library

Add RouteBuilder

Page 44: ApacheCon EU 2016 - Apache Camel the integration library

Java DSL

Page 45: ApacheCon EU 2016 - Apache Camel the integration library

Start / Stop

Page 46: ApacheCon EU 2016 - Apache Camel the integration library

Camel Main

Page 47: ApacheCon EU 2016 - 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 48: ApacheCon EU 2016 - Apache Camel the integration library

Trying Camel• Download Apache Camel 2.18.0

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

read readme.md first

Page 49: ApacheCon EU 2016 - Apache Camel the integration library

Beginner Example• camel-example-console

mvn camel:run

Page 50: ApacheCon EU 2016 - Apache Camel the integration library

Run with web console

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

http://hawt.io/maven

Page 51: ApacheCon EU 2016 - Apache Camel the integration library

Spring Boot Starter

Page 52: ApacheCon EU 2016 - Apache Camel the integration library

Spring Boot

Page 53: ApacheCon EU 2016 - Apache Camel the integration library

WildFly Swarm Generator

Page 54: ApacheCon EU 2016 - Apache Camel the integration library

WildFly Swarm CDI

Page 55: ApacheCon EU 2016 - Apache Camel the integration library

Apache ServiceMix

• Download Apache ServiceMix 7.0.0.M2• unzip apache-servicemix-7.0.0.M2.zip• cd apache-servicemix-7.0.0.M2• cd examples/camel

read readme.txt first

Page 56: ApacheCon EU 2016 - 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: ApacheCon EU 2016 - Apache Camel the integration library

What's in the Camel Box?

Page 58: ApacheCon EU 2016 - Apache Camel the integration library

Enterprise Integration Patterns

http://camel.apache.org/eip

Page 59: ApacheCon EU 2016 - Apache Camel the integration library

Splitter

Page 60: ApacheCon EU 2016 - Apache Camel the integration library

Splitter

from("file:inbox")

Page 61: ApacheCon EU 2016 - Apache Camel the integration library

Splitter

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

Page 62: ApacheCon EU 2016 - Apache Camel the integration library

Splitter

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

Custom Data Format

Page 63: ApacheCon EU 2016 - Apache Camel the integration library

Splitter

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

Custom Data Format

Page 64: ApacheCon EU 2016 - 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 -l219

Page 65: ApacheCon EU 2016 - 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 -l47

Page 66: ApacheCon EU 2016 - Apache Camel the integration library

Data Format with JAXB

• POJO class with @JAXB annotations

Page 67: ApacheCon EU 2016 - Apache Camel the integration library

Data Format with JAXB

• marshal (xml -> pojo)• unmarshal (pojo -> xml)

Page 68: ApacheCon EU 2016 - 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 -l26

Page 69: ApacheCon EU 2016 - Apache Camel the integration library

Language w/ Simple

Page 70: ApacheCon EU 2016 - Apache Camel the integration library

Language w/ Groovyhere you can do groovy

programming

Page 71: ApacheCon EU 2016 - Apache Camel the integration library

Camel DSLs

• Java DSL

• XML DSL (spring or OSGi blueprint)

• Groovy DSL

• Scala DSLGroovy and Scala

are not much in use

Java8 DSL in the works

Page 72: ApacheCon EU 2016 - Apache Camel the integration library

ProducerTemplate• Client API (alike Spring Templates)

Send a message to any Camel endpoint

Page 73: ApacheCon EU 2016 - Apache Camel the integration library

ProducerTemplate• Client API (alike Spring Templates)

FTP serverJavaApplication

How to upload a fileto a FTP server from Java code

Page 74: ApacheCon EU 2016 - Apache Camel the integration library

ProducerTemplate

FTP server

JavaApplicatio

n

Page 75: ApacheCon EU 2016 - Apache Camel the integration library

FluentProducerTemplate

FTP server

JavaApplicatio

n

Page 76: ApacheCon EU 2016 - Apache Camel the integration library

Test Kit

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

camel-test-spring camel-testng

Page 77: ApacheCon EU 2016 - Apache Camel the integration library

camel-test

Page 78: ApacheCon EU 2016 - Apache Camel the integration library

camel-testeasy to run or debug

Page 79: ApacheCon EU 2016 - Apache Camel the integration library

camel-test1) set expectations

Page 80: ApacheCon EU 2016 - Apache Camel the integration library

camel-test1) set expectations

2) send message(s)

Page 81: ApacheCon EU 2016 - Apache Camel the integration library

camel-test1) set expectations

2) send message(s)

3) assert

Page 82: ApacheCon EU 2016 - Apache Camel the integration library

Management• JMX

Page 83: ApacheCon EU 2016 - 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 currentinflight messages

Page 84: ApacheCon EU 2016 - Apache Camel the integration library

Camel Commands• Apache Karaf / ServiceMix

Page 85: ApacheCon EU 2016 - Apache Camel the integration library

Camel Commands• Spring Boot

Page 86: ApacheCon EU 2016 - Apache Camel the integration library

Rest DSL (XML)

Page 87: ApacheCon EU 2016 - Apache Camel the integration library

Rest DSL (Java)

use REST verbs to define servicesthat becomes Camel routes

Page 88: ApacheCon EU 2016 - Apache Camel the integration library

Rest DSL

configure RESTand turn on swagger api

Page 89: ApacheCon EU 2016 - Apache Camel the integration library

Swagger Doc

swagger doc as json schema

Page 90: ApacheCon EU 2016 - Apache Camel the integration library

Swagger Doc

embeddedswagger-ui

Page 91: ApacheCon EU 2016 - Apache Camel the integration library

Rest DSL Example

cd examples/camel-example-swagger-xmlmvn jetty:run

Page 92: ApacheCon EU 2016 - Apache Camel the integration library

Error Handling

Page 93: ApacheCon EU 2016 - Apache Camel the integration library

Error Handling

Page 94: ApacheCon EU 2016 - Apache Camel the integration library

Error Handling

Page 95: ApacheCon EU 2016 - Apache Camel the integration library

Error Handling

Page 96: ApacheCon EU 2016 - Apache Camel the integration library

Circuit Breaker• Netflixx Hystrix

New in Camel 2.18

Page 97: ApacheCon EU 2016 - Apache Camel the integration library

Circuit Breaker• Integrates with Hystrix Dashboard

Page 98: ApacheCon EU 2016 - Apache Camel the integration library

Maven Tooling• Archetypes

camel-archetype-java camel-archetype-componentcamel-archetype-spring camel-archetype-api-componentcamel-archetype-web camel-archetype-dataformatcamel-archetype-cdi

camel-archetype-spring-boot camel-archetype-scalacamel-archetype-blueprint camel-archetype-groovycamel-archetype-spring-dm

camel-archetype-scr camel-archetype-java8

New in Camel 2.18

Page 99: ApacheCon EU 2016 - Apache Camel the integration library

Maven Tooling• camel-maven-plugin

mvn camel:run

Page 100: ApacheCon EU 2016 - 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 101: ApacheCon EU 2016 - Apache Camel the integration library

All the other stuffType Converter Transactions

Interceptors Security

Thread Management Route Policy

Java8 DSL Asynchronous Non-Blocking Routing Engine

POJO Routing Debugging & Tracing

Page 102: ApacheCon EU 2016 - 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 103: ApacheCon EU 2016 - Apache Camel the integration library

Running CamelStandalone Web Application

Camel Spring XML JEE Application

Camel Spring Boot Apache Karaf / ServiceMix (OSGi)

Camel CDI WildFly / WildFly-Swarm(wildfly-camel)

Camel Guice vert.x(vertx-camel)

Page 104: ApacheCon EU 2016 - 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-int

egration-apache

Also videos on Youtube

@davsclausdavsclaus

[email protected]