KEMBAR78
MicroService and MicroContainer with Apache Camel | PDF
 
Design a REST Microservice
using Apache Camel
technology
Charles Moulliard (@cmoulliard)
22 Jan 2016
Who
Committer, Coder, Architect
Work on Apache Camel, Karaf, Fabric8, Hawtio, Apiman, DeltaSpike
Mountain Biker, Belgian Beer Fan
Blog:
Twitter:
Email:
http://cmoulliard.github.io
@cmoulliard
cmoulliard@redhat.com
Agenda
Integration …
Apache Camel
Micro Container
Kubernetes Service
 
Integration
Point to Point vision
Integrate many systems. Play with formats & protocols
Hub Approach
In 2003, it was reported that 70% of all EAI projects fail !
Bus
Communication done through a Bus with Normalized messages
MicroService
It is an architectural style where
an application
composed of individual
standalone services
communicating using
lightweight protocols
in event based manner



 
Apache Camel
Apache Camel
Java Integration Framework
Implements Domain Specific Language
Supports Enterprise Integration Patterns

Enterprise Patterns
implemented
and more : Loadbalancer, Throttler, Delayer, …
> 50 patterns
Route, processor
Camel project Collection of routes
Route = Processor(s) + Interceptor(s)
Producing or consuming Message

Java DSL
Fluent API, extend RouteBuilder class
importorg.apache.camel.builder.RouterBuilder;
publicclassFilterRouteextendsRouteBuilder{
publicvoidconfigure()throwsException{
from("activemq:queue:all")
.filter(xpath("/quote/product='widget'"))
.to("activemq:widget");
}
}
XML DSL
Spring, Blueprint
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-
http://camel.apache.org/schema/springhttp://camel.apache.org/schema/spring/camel-spring.xsd
">
<beanid="quotesService"class="my.cool.demo.camel.QuotesService"/>"
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<fromuri="activemq:queue:all"/>
<filter>
<xpath>"/quote/product/='widget"</xpath>
<beanid="quotesService"method="widget"/>
</filter>
</route>
</camelContext>
REST DSL
One of the components available : servlet, jetty, netty, spark, restlet,
undertow
Hostname
Port
Root of the REST Application endpoint
@Overridepublicvoidconfigure()throwsException{
restConfiguration()
.component("servlet")
.host(HOST)
.setPort(PORT);
//usetherestDSLtodefinetherestservices
rest("/users/")
.get("{id}/hello")
.route()
.process(newProcessor(){
publicvoidprocess(Exchangeexchange)throwsException{
Stringid=exchange.getIn().getHeader("id",String.class);
exchange.getOut().setBody("Hello"+id+"!Welcomefrompod:"
}
});
1
2
3
4
5
1
2
3
4
Container agnostic
Endpoints registered
CamelContext
Policy
Security
Lifecycle
Tracing
JMX
Threads can be configured

 
Demo
 
Docker Container
Process
Docker
Union FS mounted with immutable images
Benefits: portability, reusability, versioning, application-centric
Docker config
Docker
Container runtime, Process launcher
Maven Docker Plugin
docker:build Build image of app
docker:push Push image


<docker.from>fabric8/s2i-java:1.2</docker.from>
<docker.image>${docker.registryPrefix}fabric8/${project.artifactId}:${project.version}
<docker.port.container.jolokia>8778</docker.port.container.jolokia>
<docker.registryPrefix>${env.DOCKER_REGISTRY}/</docker.registryPrefix>
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.maven.plugin.version}</version>
<configuration>
<images>
<image>
<name>${docker.image}</name>
<build>
<from>${docker.from}</from>
<assembly>
<basedir>/deployments</basedir>
<descriptorRef>hawt-app</descriptorRef>
</assembly>
<env>
<JAVA_LIB_DIR>/deployments/lib</JAVA_LIB_DIR>
<JAVA_MAIN_CLASS>org.apache.camel.cdi.Main</JAVA_MAIN_CLASS>
</env>
 
With Docker
 
 
Kubernetes & Openshift
Kubernetes
Runtime & Operational management of containers
ApiServer (event, status)
Scheduler, Controller & State Storage
Agent - Kubelet - manage containers on host
Containers pods (= shared docker containers)
Kubernetes
Pod & docker
Communicate to each other using skyDNS to resolve hostname
Pod & port
Ports can be exposed
Pod & volume
Share data using mounted volume between host & container
Kubernetes Service
Kube Service loadbalanced through the pods using HA-Proxy Routes map
private with public IP address
Kube Application JSon
 
Fabric8
Fabric8 Maven Plugin
fabric8:json generates Kube MetaData
fabric8:apply deploy on Openshift


<fabric8.service.name>hellorest</fabric8.service.name>
<fabric8.service.port>9090</fabric8.service.port>
<fabric8.service.containerPort>8080</fabric8.service.containerPort>
<fabric8.label.component>${project.artifactId}</fabric8.label.component>
<fabric8.label.container>tomcat</fabric8.label.container>
<fabric8.label.group>demo</fabric8.label.group>
<fabric8.service.type>LoadBalancer</fabric8.service.type>
<fabric8.iconRef>camel</fabric8.iconRef>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${fabric8.version}</version>
<executions>
<execution>
<id>json</id>
<goals>
<goal>json</goal>
</goals>
 
With OpenShift & Kubernetes
 
Questions
Twitter :
Camel Rest MicroService in Action
@cmoulliard

https://github.com/FuseByExample/microservice-camel-in-action
http://fabric8.io/

MicroService and MicroContainer with Apache Camel