Developing Microservices with Apache Camel

davsclaus 6,861 views 101 slides Apr 20, 2016
Slide 1
Slide 1 of 101
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101

About This Presentation

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...


Slide Content

Microservices with Apache Camel
Claus Ibsen (@davsclaus)
Principal Software Engineer, Red Hat

Your Speaker

Your Speaker
●Principal Software Engineer at Red Hat
●Apache Camel
●7 years working with Camel
●Author of Camel in Action books
●Contact
●E-mail: [email protected]
●Twitter: @davsclaus
●Blog: http://davsclaus.com

Shameful Advertisement
http://manning.com/ibsen2
Coupon Code
(39% discount)
camel39

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Standalone
●with Docker
●with OpenShift 3 / Kubernetes
●More Information

What is Apache Camel?
●Quote from the website

What is Apache Camel?
●Integration Framework

What is Apache Camel?
●What is Enterprise Integration Patterns?
It's a book

What is Apache Camel?
●Enterprise Integration Patterns
http://camel.apache.org/eip

What is Apache Camel?
●EIP - Content Based Router

What is Apache Camel?
from newOrder

What is Apache Camel?
from newOrder
choice

What is Apache Camel?
from newOrder
choice
when isWidget to widget

What is Apache Camel?
from newOrder
choice
when isWidget to widget
otherwise to gadget

What is Apache Camel?
from(newOrder)
choice
when(isWidget) to(widget)
otherwise to(gadget)

What is Apache Camel?
from(newOrder)
.choice()
.when(isWidget).to(widget)
.otherwise().to(gadget);

What is Apache Camel?
Endpoint newOrder = endpoint("activemq:queue:newOrder");
from(newOrder)
.choice()
.when(isWidget).to(widget)
.otherwise().to(gadget);

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

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

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

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

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

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>

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

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

What is Apache Camel?
●Java DSL is just Java

What is Apache Camel?
●XML DSL is just XML
●… with XSD schema for validation/tooling

What is Apache Camel?
●Camel's Architecture

What is Apache Camel?
150+ Components

What is Apache Camel?
150+ Components

+

+
+

+
+
+

=
+
+
+

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Standalone
●with Docker
●with OpenShift 3 / Kubernetes
●More Information

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

Camel Microservices
●Apache Karaf

Camel Microservices
●Apache Karaf
Apache Karaf
(boot)

Camel Microservices
●Apache Karaf
Karaf Features
OSGi Bundles
Apache Karaf
(boot)

Camel Microservices
●Apache Karaf
Karaf Features
OSGi Bundles
Apache Karaf
(boot)
Karaf Maven
Plugin

Camel Microservices
●Apache Karaf
Karaf Features
OSGi Bundles
Apache Karaf
(boot)
Karaf Maven
Plugin
Custom Karaf
(with your app)
tar / zip file

Camel Microservices
●Rest DSL
●Use Rest verbs
GET
POST
PUT
...
●Swagger API
●Pluggable Transport

Rest DSL example

Rest DSL example

Rest DSL example

Rest DSL example - add Swagger API

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Hello Service
●Create the Camel projects
●Docker
●OpenShift v3
●More Information

Demo - Hello Service
Hello Service

Demo - Hello Service
Hello Service
Hi I am New York. Hello Claus how are you today?
name=Claus

Demo - Hello Service
Java Standalone Apache Tomcat
HTTP
Hello Service

Demo - Hello Service
Java Standalone Apache Tomcat
HTTP
from timer
to http
to log
from servlet
transform
Hello Service

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

Demo - Create the Camel Projects
●Using Command Shell
●From Eclipse

Demo - Create the Camel Projects
●camel-archetype-web
Ready to use
out of the box

Demo - Create the Camel Projects
●camel-archetype-cdi
Not ready
We need to change
he code

Demo - Create the Camel Projects
●add netty4-http endpoint
CMD + ALT
4

Demo - Create the Camel Projects
● configure netty4-http endpoint

Demo - Create the Camel Projects
●change route to call netty

Demo - Create the Camel Projects
●change bean to return a name

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

Demo - Running Standalone
mvn camel:run

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Hello Service
●Create the Camel projects
●Docker
●OpenShift v3
●More Information

Camel and Docker
Maven Project
Docker Maven
Plugin
Docker Image
build

Add Docker from Command Line

Add Docker from Eclipse / IDEA
CMD + ALT
4

Docker Maven Plugin in pom.xml

Build Docker Containers
●mvn clean install docker:build

Build Docker Containers
●After build images in local Docker repository
camel-archetype-cdi
camel-archetype-web

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Hello Service
●Create the Camel projects
●Docker
●OpenShift v3
●More Information

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

Dynamic
●camel-archetype-cdi camel-archetype-web
Java Standalone Apache Tomcat
from timer
to http
to log
from servlet
transform
S
e
r
v
i
c
e
Kubernetes
Service

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

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
k
u
b
e
-
p
r
o
x
y
Kubernetes
Master
service
changes
S
e
r
v
i
c
e
enlist

Define Kubernetes Service
●Use fabric8
command
Apache Tomcat
from servlet
transform
S
e
r
v
i
c
e

Define Kubernetes Service
●Defined in pom.xml in <properties>
Apache Tomcat
from servlet
transform
S
e
r
v
i
c
e
Container Port = Inside Docker Container
(e.g. the port of Apache Tomcat)
Service Port = Outside
Consumers of Service to use
Name of service

Generated kubernetes.json
Apache Tomcat
from http
choice
setBody
S
e
r
v
i
c
e

Use Kubernetes Services
Java Standalone
from timer
to http
to log
●Environment Variables
●Hostname
●Port
Injected by Kubernetes
when starting a pod

Camel - Use Kubernetes Service
●Use {{service:name}} in Camel
Java Standalone
from timer
to http
to log

Microservice Demo - Ready for launch!
●camel-archetype-cdi camel-archetype-web
Java Standalone Apache Tomcat
from timer
to http
to log
from http
transform
S
e
r
v
i
c
e
Service defined
Ready to deploy to Kubernetes

Deploy - myweb
●mvn -Pf8-local-deploy
Apache Tomcat
from http
transform
S
e
r
v
i
c
e

Deploy - camel-archetype-cdi
●mvn -Pf8-local-deploy
Java Standalone
from timer
to http
to log

fabric8 web console
●http://fabric8.vagrant.f8

OpenShift 3 CLI
●oc get pods
docker CLI is also possible
docker images
docker ps

OpenShift 3 CLI
●oc get services

OpenShift 3 CLI
●oc logs -f <pod-name>

OpenShift 3 CLI
●oc get routes

Scaling up / down
●change controller replicas

Scaling up / down
●Service Load Balancing

Agenda
●What is Apache Camel?
●Camel Microservices
●Demo
●Hello Service
●Create the Camel projects
●Docker
●OpenShift v3
●More Information

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