Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Apache Camel - The integration library

2,253 views

Published on

We start with an introduction to what Apache Camel is, and how you can use Camel to make integration much easier. Allowing you to focus on your business logic, rather than low level messaging protocols, and transports.

You will hear how Apache Camel is related Enterprise Integration
Patterns which you can use in your architectural designs and as well in Java or XML code, running on the JVM with Camel.

You will also hear what other features Camel provides out of the box, which can make integration much easier for you.

We also take a moment to look at web console tooling that allows you to get insight into your running Apache Camel applications, which has among others visual route diagrams with tracing/debugging and profiling capabilities. In addition to the web tooling we will also show you other tools in the making.

This talk was presented at JDKIO on September 13th 2016.

Published in: Internet

Apache Camel - The integration library

  1. 1. Apache Camel The Integration Library @davsclaus davsclaus davsclaus.com Claus Ibsen
  2. 2. Claus Ibsen • Principal Software Engineer
 at Red Hat • Apache Camel
 8 years working with Camel • Author of
 Camel in Action books @davsclaus davsclaus davsclaus.com
  3. 3. Agenda • What is Apache Camel? • Little Example • Trying Apache Camel • What's in the Camel Box? • Running Camel • More Information
  4. 4. What is Apache Camel? • Quote from the website Apache Camel is a powerful Open Source Integration Framework based on Enterprise Integration Patterns
  5. 5. What is Apache Camel? • Quote from the website Apache Camel is a powerful Open Source Integration Framework based on Enterprise Integration Patterns
  6. 6. Integration Framework
  7. 7. Enterprise Integration Patterns
  8. 8. Enterprise Integration Patterns
  9. 9. Content Based Router
  10. 10. Content Based Router from newOrder
  11. 11. Content Based Router from newOrder choice
  12. 12. Content Based Router from newOrder choice when isWidget to widget
  13. 13. Content Based Router from newOrder choice when isWidget to widget otherwise to gadget
  14. 14. Content Based Router from(newOrder) choice when(isWidget) to(widget) otherwise to(gadget)
  15. 15. Content Based Router from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
  16. 16. Content Based Router Endpoint newOrder = endpoint("activemq:queue:newOrder"); from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
  17. 17. 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);
  18. 18. 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);
  19. 19. 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); }
  20. 20. Java Code import 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); } }
  21. 21. 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"); } }
  22. 22. 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>
  23. 23. 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
  24. 24. 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
  25. 25. Just Java Code
  26. 26. Just XML
  27. 27. Architecture
  28. 28. Components ahc bindy coap docker ahc-ws blueprint cometd dozer apns boon context dropbox atmosphere box couchdb eclipse atom cache crypto ejb aws cassandraql csv elasticsearch bam castor cfx elsql bean-validator cdi cxf-transport eventadmin beanio chunk disruptor exec beanstalk cmis dns facebook
  29. 29. Components flatpack google-drive hbase jacksonxml fop google-mail hdfs jasypt freemarker gora hdfs2 javaspace ftp grape http jaxb gae groovy http4 jbpm ganglia gson ibatis jclouds geocoder guava-eventbus ical jcr git guice infinispan jdbc github hawtdb irc jetty8 google-calendar hazelcast jackson jetty9
  30. 30. Components jgroups jsonpath leveldb mustache jibx jt400 linkedin mvel jing juel lucene mybatis jira jxpath mail netty jms kafka metrics netty-http jmx kestrel mina netty4 jolt krati mina2 netty4-http josql kubernetes mongodb ognl jpa kura mqtt olingo2 jsch ldap msv openshift
  31. 31. Components optaplanner rabbitmq scala smpp paho restlet schematron snpp paxlogging rmi scr soap pdf routebox script solr pgevent rss servlet spark-rest printer ruby servletlistener spring protobuf rx shiro spring-batch quartz salesforce sip spring-boot quarz2 sap-netweaver sjms spring-integration quickfix saxon slack spring-javaconfig
  32. 32. Components spring-ldap swagger undertow xmlsecurity spring-redis swagger-java univocity xmpp spring-security syslog urlrewrite xstream spring-ws tagsoup velocity yammer sql tarfile vertx zipfile ssh test weather zookeeper stax test-blueprint websocket stomp test-spring xmlbeans stream testng xmljson stringtemplate twitter xmlrpc
  33. 33. +
  34. 34. + +
  35. 35. + + +
  36. 36. + + + =
  37. 37. Apache Camel 1.0
  38. 38. Apache Camel 2.17.3
  39. 39. Pop Quizz How long time between the first and the latest release ?
  40. 40. Pop Quizz 9 years
  41. 41. Agenda • What is Apache Camel? • Little Example • Trying Apache Camel • What's in the Camel Box? • Running Camel • More Information
  42. 42. File Copier Example
  43. 43. Public Static Void Main
  44. 44. Create CamelContext
  45. 45. Add RouteBuilder
  46. 46. Java DSL
  47. 47. Start / Stop
  48. 48. Camel Main
  49. 49. Agenda • What is Apache Camel? • Little Example • Trying Apache Camel • What's in the Camel Box? • Running Camel • More Information
  50. 50. 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
  51. 51. Beginner Example • camel-example-console mvn camel:run
  52. 52. Run with web console mvn io.hawt:hawtio-maven-plugin:1.4.65:camel http://hawt.io/maven
  53. 53. Spring Boot Starter
  54. 54. WildFly Swarm Generator
  55. 55. Agenda • What is Apache Camel? • Little Example • Trying Apache Camel • What's in the Camel Box? • More Information
  56. 56. What's in the Camel Box?
  57. 57. Enterprise Integration Patterns http://camel.apache.org/eip
  58. 58. Pipes and Filters EIP from("file:inbox") .pipeline() .to("bean:decrypt") .to("bean:authenticate") .to("bean:de-dup");
  59. 59. 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
  60. 60. 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"
  61. 61. 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"
  62. 62. 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"
  63. 63. 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"
  64. 64. Splitter
  65. 65. Splitter from("file:inbox")
  66. 66. Splitter from("file:inbox") .split(body().tokenize("n"))
  67. 67. Splitter from("file:inbox") .split(body().tokenize("n")) .marshal(customToXml) Custom Data Format
  68. 68. Splitter from("file:inbox") .split(body().tokenize("n")) .marshal(customToXml) .to("activemq:line"); Custom Data Format
  69. 69. Components ahc bindy coap docker ahc-ws blueprint cometd dozer apns boon context dropbox atmosphere box couchdb eclipse atom cache crypto ejb aws cassandraql csv elasticsearch bam castor cfx elsql bean-validator cdi cxf-transport eventadmin beanio chunk disruptor exec beanstalk cmis dns facebook camel-catalog:component-list | wc -l 218
  70. 70. Data Formats avro flatpack pgp univocity-fixed barcode gzip protobuf univocity-tsv base64 hl7 rss xmlBeans beanio ical secureXML xmjson bindy-csv jacksonxml serialization xmlrpc bindy-fixed jaxb soapjaxb xstream bindy-kvp jibx string zip boon json-gson syslog zipfile castor json-jackson tarfile crypto json-xstream tidyMarkup csv mime-multipart univocity-csv camel-catalog:dataformat-list | wc -l 47
  71. 71. Data Format with JAXB • POJO class with @JAXB annotations
  72. 72. Data Format with JAXB • marshal (xml -> pojo) • unmarshal (pojo -> xml)
  73. 73. Languages bean header php sql constant javaScript python terser el jsonpath ref tokenize exchange
 Property jxpath ruby xpath file mvel simple xquery groovy ognl spel xtokenize camel-catalog:language-list | wc -l 26
  74. 74. Language w/ Simple
  75. 75. Language w/ Groovy here you can do groovy programming
  76. 76. Camel DSLs • Java DSL • XML DSL (spring or OSGi blueprint) • Groovy DSL • Scala DSL Groovy and Scala
 are not much in use
  77. 77. ProducerTemplate • Client API (alike Spring Templates) Send a message to any Camel endpoint
  78. 78. ProducerTemplate • Client API (alike Spring Templates) FTP server Java Application How to upload a file to a FTP server from Java code
  79. 79. ProducerTemplate FTP server Java Application
  80. 80. FluentProducerTemplate FTP server Java Application
  81. 81. Test Kit camel-test camel-test-blueprint camel-test-cdi camel-test-karaf camel-test-spring camel-testng
  82. 82. camel-test
  83. 83. camel-test easy to run or debug
  84. 84. camel-test 1) set expectations
  85. 85. camel-test 1) set expectations 2) send message(s)
  86. 86. camel-test 1) set expectations 2) send message(s) 3) assert
  87. 87. Management • JMX
  88. 88. • 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
  89. 89. Camel Commands • Apache Karaf / ServiceMix / JBoss Fuse
 
 
 
 

  90. 90. Camel Commands • Spring Boot
  91. 91. Rest DSL use REST verbs to define services that becomes Camel routes
  92. 92. Rest DSL configure REST and turn on swagger api
  93. 93. Rest DSL cd examples/camel-example-swagger-xml mvn jetty:run
  94. 94. Rest DSL swagger doc as json schema
  95. 95. Rest DSL embedded swagger-ui
  96. 96. Error Handling
  97. 97. Error Handling
  98. 98. Error Handling
  99. 99. Error Handling
  100. 100. Circuit Breaker • Netflixx Hystrix New in Camel 2.18
  101. 101. Circuit Breaker • Integrates with Hystrix Dashboard
  102. 102. Maven Tooling • Archetypes camel-archetype-java camel-archetype-component camel-archetype-spring camel-archetype-api-component camel-archetype-web camel-archetype-dataformat camel-archetype-cdi camel-archetype-spring-boot camel-archetype-scala camel-archetype-blueprint camel-archetype-groovy camel-archetype-spring-dm camel-archetype-scr camel-archetype-java8 New in Camel 2.18
  103. 103. Maven Tooling • camel-maven-plugin mvn camel:run
  104. 104. Maven Tooling • fabric8-camel-maven-plugin mvn fabric8-camel:validate http://fabric8.io/guide/camelMavenPlugin.html Validate your Camel uris from the source
  105. 105. All the other stuff Type Converter Transactions Interceptors Security Thread Management Route Policy Reactive Asynchronous Non-Blocking Routing Engine POJO Routing Debugging & Tracing
  106. 106. Agenda • What is Apache Camel? • Little Example • Trying Apache Camel • What's in the Camel Box? • Running Camel • More Information
  107. 107. Running Camel Standalone Web Application Camel Spring XML JEE Application Camel Spring Boot Apache Karaf (OSGi) Camel CDI Wildfly
 (wildfly-camel) Camel Guice vert.x
 (vertx-camel)
  108. 108. 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

×