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.

Developing Microservices with Apache Camel

5,491 views

Published on

Red Hat Microservices Architecture Day - New York, November 2015. Presented by Claus Ibsen.

Apache Camel is a very popular integration library that works very well with microservice architecture. This talk introduces you to Apache Camel and how you can easily get started with Camel on your computer. Then we cover how to create new Camel projects from scratch as microservices, which you can boot using Camel or Spring Boot, or other micro containers such as Jetty or fat JARs. We then take a look at what options you have for monitoring and managing your Camel microservices using tooling such as Jolokia, and hawtio web console.

Published in: Internet

Developing Microservices with Apache Camel

  1. 1. Microservices with Apache Camel Claus Ibsen (@davsclaus) Principal Software Engineer, Red Hat
  2. 2. Your Speaker
  3. 3. Your Speaker ● Principal Software Engineer at Red Hat ● Apache Camel ● 7 years working with Camel ● Author of Camel in Action books ● Contact ● E-mail: cibsen@redhat.com ● Twitter: @davsclaus ● Blog: http://davsclaus.com
  4. 4. Shameful Advertisement http://manning.com/ibsen2 Coupon Code (39% discount) camel39
  5. 5. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Standalone ● with Docker ● with OpenShift 3 / Kubernetes ● More Information
  6. 6. What is Apache Camel? ● Quote from the website
  7. 7. What is Apache Camel? ● Integration Framework
  8. 8. What is Apache Camel? ● What is Enterprise Integration Patterns? It's a book
  9. 9. What is Apache Camel? ● Enterprise Integration Patterns http://camel.apache.org/eip
  10. 10. What is Apache Camel? ● EIP - Content Based Router
  11. 11. What is Apache Camel? from newOrder
  12. 12. What is Apache Camel? from newOrder choice
  13. 13. What is Apache Camel? from newOrder choice when isWidget to widget
  14. 14. What is Apache Camel? from newOrder choice when isWidget to widget otherwise to gadget
  15. 15. What is Apache Camel? from(newOrder) choice when(isWidget) to(widget) otherwise to(gadget)
  16. 16. What is Apache Camel? from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
  17. 17. What is Apache Camel? Endpoint newOrder = endpoint("activemq:queue:newOrder"); from(newOrder) .choice() .when(isWidget).to(widget) .otherwise().to(gadget);
  18. 18. 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);
  19. 19. 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);
  20. 20. 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(); }
  21. 21. What is Apache Camel? ● 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) .end(); } }
  22. 22. 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(); } }
  23. 23. 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>
  24. 24. 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
  25. 25. 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
  26. 26. What is Apache Camel? ● Java DSL is just Java
  27. 27. What is Apache Camel? ● XML DSL is just XML ● … with XSD schema for validation/tooling
  28. 28. What is Apache Camel? ● Camel's Architecture
  29. 29. What is Apache Camel? 150+ Components
  30. 30. What is Apache Camel? 150+ Components
  31. 31. +
  32. 32. + +
  33. 33. + + +
  34. 34. = + + +
  35. 35. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Standalone ● with Docker ● with OpenShift 3 / Kubernetes ● More Information
  36. 36. Running Camel as Microservices Standalone Web Application Camel Spring XML Apache Karaf Camel Spring Boot Wildfly (wildfly-camel) Camel CDI vert.x (vertx-camel) Camel Guice Rest DSL
  37. 37. Camel Microservices ● Apache Karaf
  38. 38. Camel Microservices ● Apache Karaf Apache Karaf (boot)
  39. 39. Camel Microservices ● Apache Karaf Karaf Features OSGi Bundles Apache Karaf (boot)
  40. 40. Camel Microservices ● Apache Karaf Karaf Features OSGi Bundles Apache Karaf (boot) Karaf Maven Plugin
  41. 41. Camel Microservices ● Apache Karaf Karaf Features OSGi Bundles Apache Karaf (boot) Karaf Maven Plugin Custom Karaf (with your app) tar / zip file
  42. 42. Camel Microservices ● Rest DSL ● Use Rest verbs GET POST PUT ... ● Swagger API ● Pluggable Transport
  43. 43. Rest DSL example
  44. 44. Rest DSL example
  45. 45. Rest DSL example
  46. 46. Rest DSL example - add Swagger API
  47. 47. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Hello Service ● Create the Camel projects ● Docker ● OpenShift v3 ● More Information
  48. 48. Demo - Hello Service Hello Service
  49. 49. Demo - Hello Service Hello Service Hi I am New York. Hello Claus how are you today? name=Claus
  50. 50. Demo - Hello Service Java Standalone Apache Tomcat HTTP Hello Service
  51. 51. Demo - Hello Service Java Standalone Apache Tomcat HTTP from timer to http to log from servlet transform Hello Service
  52. 52. Demo - Create the Camel Projects Java Standalone Apache Tomcat HTTP from timer to http to log from servlet transform Hello Service camel-archetype-cdi camel-archetype-web
  53. 53. Demo - Create the Camel Projects ● Using Command Shell ● From Eclipse
  54. 54. Demo - Create the Camel Projects ● camel-archetype-web Ready to use out of the box
  55. 55. Demo - Create the Camel Projects ● camel-archetype-cdi Not ready We need to change he code
  56. 56. Demo - Create the Camel Projects ● add netty4-http endpoint CMD + ALT 4
  57. 57. Demo - Create the Camel Projects ● configure netty4-http endpoint
  58. 58. Demo - Create the Camel Projects ● change route to call netty
  59. 59. Demo - Create the Camel Projects ● change bean to return a name
  60. 60. Demo - Overview ● camel-archetype-cdi camel-archetype-web Java Standalone Apache Tomcat HTTP 8080 from timer to http to log from http transform We are ready to run standalone
  61. 61. Demo - Running Standalone mvn camel:run
  62. 62. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Hello Service ● Create the Camel projects ● Docker ● OpenShift v3 ● More Information
  63. 63. Camel and Docker Maven Project Docker Maven Plugin Docker Image build
  64. 64. Add Docker from Command Line
  65. 65. Add Docker from Eclipse / IDEA CMD + ALT 4
  66. 66. Docker Maven Plugin in pom.xml
  67. 67. Build Docker Containers ● mvn clean install docker:build
  68. 68. Build Docker Containers ● After build images in local Docker repository camel-archetype-cdi camel-archetype-web
  69. 69. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Hello Service ● Create the Camel projects ● Docker ● OpenShift v3 ● More Information
  70. 70. Static ● camel-archetype-cdi camel-archetype-web Java Standalone Apache Tomcat from timer to http to log from servlet transform HTTP 8080 hostname:port is static / hardcoded
  71. 71. Dynamic ● camel-archetype-cdi camel-archetype-web Java Standalone Apache Tomcat from timer to http to log from servlet transform Service Kubernetes Service
  72. 72. What is a Kubernetes Service ● Network Connection to one or more Pods ● Own fixed IP address and port http://fabric8.io/guide/services.html http://kubernetes.io/v1.1/docs/user-guide/services.html
  73. 73. What is a Kubernetes Service ● kube-proxy on client http://fabric8.io/guide/services.html http://kubernetes.io/v1.1/docs/user-guide/services.html Java Standalone Apache Tomcat from timer to http to log from servlet transform kube-proxy Kubernetes Master service changes Service enlist
  74. 74. Define Kubernetes Service ● Use fabric8 command Apache Tomcat from servlet transform Service
  75. 75. Define Kubernetes Service ● Defined in pom.xml in <properties> Apache Tomcat from servlet transform Service Container Port = Inside Docker Container (e.g. the port of Apache Tomcat) Service Port = Outside Consumers of Service to use Name of service
  76. 76. Generated kubernetes.json Apache Tomcat from http choice setBody Service
  77. 77. Use Kubernetes Services Java Standalone from timer to http to log ● Environment Variables ● Hostname ● Port Injected by Kubernetes when starting a pod
  78. 78. Camel - Use Kubernetes Service ● Use {{service:name}} in Camel Java Standalone from timer to http to log
  79. 79. Microservice Demo - Ready for launch! ● camel-archetype-cdi camel-archetype-web Java Standalone Apache Tomcat from timer to http to log from http transform Service Service defined Ready to deploy to Kubernetes
  80. 80. Deploy - myweb ● mvn -Pf8-local-deploy Apache Tomcat from http transform Service
  81. 81. Deploy - camel-archetype-cdi ● mvn -Pf8-local-deploy Java Standalone from timer to http to log
  82. 82. fabric8 web console ● http://fabric8.vagrant.f8
  83. 83. OpenShift 3 CLI ● oc get pods docker CLI is also possible docker images docker ps
  84. 84. OpenShift 3 CLI ● oc get services
  85. 85. OpenShift 3 CLI ● oc logs -f <pod-name>
  86. 86. OpenShift 3 CLI ● oc get routes
  87. 87. Scaling up / down ● change controller replicas
  88. 88. Scaling up / down ● Service Load Balancing
  89. 89. Agenda ● What is Apache Camel? ● Camel Microservices ● Demo ● Hello Service ● Create the Camel projects ● Docker ● OpenShift v3 ● More Information
  90. 90. More information ● Apache Camel Microservices ● http://camel.apache.org/camel-boot ● Fabric8 ● http://fabric8.io ● chat room #fabric8 on freenode ● Medium Fabric8 (blogs and videos) ● https://medium.com/fabric8-io

×