MicroService and MicroContainer with Apache Camel

38
Design a REST Microservice using Apache Camel technology Charles Moulliard (@cmoulliard) 22 Jan 2016

Transcript of MicroService and MicroContainer with Apache Camel

Page 1: MicroService and MicroContainer with Apache Camel

 

Design a REST Microserviceusing Apache Cameltechnology

Charles Moulliard (@cmoulliard)22 Jan 2016

Page 2: MicroService and MicroContainer with Apache Camel

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

[email protected]

Page 3: MicroService and MicroContainer with Apache Camel

Agenda

Integration …

Apache Camel

Micro Container

Kubernetes Service

Page 4: MicroService and MicroContainer with Apache Camel

 

Integration

Page 5: MicroService and MicroContainer with Apache Camel

Point to Point vision

Integrate many systems. Play with formats & protocols

Page 6: MicroService and MicroContainer with Apache Camel

Hub Approach

In 2003, it was reported that 70% of all EAI projects fail !

Page 7: MicroService and MicroContainer with Apache Camel

Bus

Communication done through a Bus with Normalized messages

Page 8: MicroService and MicroContainer with Apache Camel

MicroService

It is an architectural style wherean application

composed of individualstandalone services

communicating usinglightweight protocols

in event based manner

Page 9: MicroService and MicroContainer with Apache Camel

 

Apache Camel

Page 10: MicroService and MicroContainer with Apache Camel

Apache Camel

Java Integration Framework

Implements Domain Specific Language

Supports Enterprise Integration Patterns

Page 11: MicroService and MicroContainer with Apache Camel

Enterprise Patterns

implemented

and more : Loadbalancer, Throttler, Delayer, …

> 50 patterns

Page 12: MicroService and MicroContainer with Apache Camel

Route, processor

Camel project Collection of routes

Route = Processor(s) + Interceptor(s)

Producing or consuming Message

Page 13: MicroService and MicroContainer with Apache Camel

Java DSL

Fluent API, extend RouteBuilder class

import org.apache.camel.builder.RouterBuilder;

public class FilterRoute extends RouteBuilder {

public void configure() throws Exception {

from("activemq:queue:all") .filter(xpath("/quote/product = 'widget'")) .to("activemq:widget"); } }

Page 14: MicroService and MicroContainer with Apache Camel

XML DSL

Spring, Blueprint

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd ">

<bean id="quotesService" class="my.cool.demo.camel.QuotesService"/>"

<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:queue:all"/> <filter> <xpath>"/quote/product/ = 'widget"</xpath> <bean id="quotesService" method="widget"/> </filter> </route> </camelContext>

Page 15: MicroService and MicroContainer with Apache Camel

REST DSL

One of the components available : servlet, jetty, netty, spark, restlet,undertow

Hostname

Port

Root of the REST Application endpoint

@Override public void configure() throws Exception {

restConfiguration() .component("servlet") .host(HOST) .setPort(PORT);

// use the rest DSL to define the rest services rest("/users/") .get("{id}/hello") .route() .process(new Processor() { public void process(Exchange exchange) throws Exception { String id = exchange.getIn().getHeader("id", String.class); exchange.getOut().setBody("Hello " + id + "! Welcome from pod : " } });

1

2

3

4

5

1

2

3

4

Page 16: MicroService and MicroContainer with Apache Camel

Container agnostic

Endpoints registered CamelContext

Policy

Security

Lifecycle

Tracing

JMX

Threads can be configured

Page 17: MicroService and MicroContainer with Apache Camel

 

Demo

Page 18: MicroService and MicroContainer with Apache Camel

 

Docker Container

Page 19: MicroService and MicroContainer with Apache Camel

Process

Page 20: MicroService and MicroContainer with Apache Camel

Docker

Union FS mounted with immutable images

Benefits: portability, reusability, versioning, application-centric

Page 21: MicroService and MicroContainer with Apache Camel

Docker config

Page 22: MicroService and MicroContainer with Apache Camel

Docker

Container runtime, Process launcher

Page 23: MicroService and MicroContainer with Apache Camel

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>

Page 24: MicroService and MicroContainer with Apache Camel

 

With Docker

Page 25: MicroService and MicroContainer with Apache Camel

 

Page 26: MicroService and MicroContainer with Apache Camel

 

Kubernetes & Openshift

Page 27: MicroService and MicroContainer with Apache Camel

Kubernetes

Runtime & Operational management of containers

ApiServer (event, status)

Scheduler, Controller & State Storage

Agent - Kubelet - manage containers on host

Containers pods (= shared docker containers)

Page 28: MicroService and MicroContainer with Apache Camel

Kubernetes

Page 29: MicroService and MicroContainer with Apache Camel

Pod & docker

Communicate to each other using skyDNS to resolve hostname

Page 30: MicroService and MicroContainer with Apache Camel

Pod & port

Ports can be exposed

Page 31: MicroService and MicroContainer with Apache Camel

Pod & volume

Share data using mounted volume between host & container

Page 32: MicroService and MicroContainer with Apache Camel

Kubernetes Service

Kube Service loadbalanced through the pods using HA-Proxy Routes mapprivate with public IP address

Page 33: MicroService and MicroContainer with Apache Camel

Kube Application JSon

Page 34: MicroService and MicroContainer with Apache Camel

 

Fabric8

Page 35: MicroService and MicroContainer with Apache Camel

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>

Page 36: MicroService and MicroContainer with Apache Camel

 

With OpenShift & Kubernetes

Page 37: MicroService and MicroContainer with Apache Camel

 

Page 38: MicroService and MicroContainer with Apache Camel

Questions

Twitter :

Camel Rest MicroService in Action

@cmoulliard

https://github.com/FuseByExample/microservice-camel-in-action

http://fabric8.io/