ApacheCon EU 2016 - Apache Camel the integration library

Preview:

Citation preview

Apache CamelThe Integration

Library

EU 2016

Claus Ibsen

Claus Ibsen• Senior Principal Software Engineer

at Red Hat

• Apache Camel8+ years commiter and PMC member

• Author ofCamel in Action books

@davsclausdavsclaus

davsclaus.comclaus.ibsen@gmail.com

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

What is Apache Camel?

• Quote from the website

Apache Camel is apowerful Open SourceIntegration Framework

based onEnterprise Integration Patterns

What is Apache Camel?

• Quote from the website

Apache Camel is apowerful Open SourceIntegration Framework

based onEnterprise Integration Patterns

Integration Framework

Enterprise Integration Patterns

Enterprise Integration Patterns

Content Based Router

Content Based Router

from newOrder

Content Based Router

from newOrder choice

Content Based Router

from newOrder choice when isWidget to widget

Content Based Router

from newOrder choice when isWidget to widget otherwise to gadget

Content Based Router

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

Content Based Router

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

Content Based Router

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

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

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

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

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

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

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

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>

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

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

Just Java Code

Just XML

Architecture

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

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

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

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

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

+

+

+

+

+

+

+

+

+ =

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

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

File Copier Example

Public Static Void Main

Create CamelContext

Add RouteBuilder

Java DSL

Start / Stop

Camel Main

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

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

Beginner Example• camel-example-console

mvn camel:run

Run with web console

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

http://hawt.io/maven

Spring Boot Starter

Spring Boot

WildFly Swarm Generator

WildFly Swarm CDI

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

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• More Information

What's in the Camel Box?

Enterprise Integration Patterns

http://camel.apache.org/eip

Splitter

Splitter

from("file:inbox")

Splitter

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

Splitter

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

Custom Data Format

Splitter

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

Custom Data Format

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

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

Data Format with JAXB

• POJO class with @JAXB annotations

Data Format with JAXB

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

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

Language w/ Simple

Language w/ Groovyhere you can do groovy

programming

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

ProducerTemplate• Client API (alike Spring Templates)

Send a message to any Camel endpoint

ProducerTemplate• Client API (alike Spring Templates)

FTP serverJavaApplication

How to upload a fileto a FTP server from Java code

ProducerTemplate

FTP server

JavaApplicatio

n

FluentProducerTemplate

FTP server

JavaApplicatio

n

Test Kit

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

camel-test-spring camel-testng

camel-test

camel-testeasy to run or debug

camel-test1) set expectations

camel-test1) set expectations

2) send message(s)

camel-test1) set expectations

2) send message(s)

3) assert

Management• JMX

• 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

Camel Commands• Apache Karaf / ServiceMix

Camel Commands• Spring Boot

Rest DSL (XML)

Rest DSL (Java)

use REST verbs to define servicesthat becomes Camel routes

Rest DSL

configure RESTand turn on swagger api

Swagger Doc

swagger doc as json schema

Swagger Doc

embeddedswagger-ui

Rest DSL Example

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

Error Handling

Error Handling

Error Handling

Error Handling

Circuit Breaker• Netflixx Hystrix

New in Camel 2.18

Circuit Breaker• Integrates with Hystrix Dashboard

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

Maven Tooling• camel-maven-plugin

mvn camel:run

Maven Tooling• fabric8-camel-maven-plugin

mvn fabric8-camel:validate

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

Validate your Camel uris

from the source

All the other stuffType Converter Transactions

Interceptors Security

Thread Management Route Policy

Java8 DSL Asynchronous Non-Blocking Routing Engine

POJO Routing Debugging & Tracing

Agenda• What is Apache Camel?

• Little Example

• Trying Apache Camel

• What's in the Camel Box?

• Running Camel

• More Information

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)

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

davsclaus.comclaus.ibsen@gmail.com