Developing Micro-Services for Cloud using Java

Preview:

Citation preview

Developing Microservices for Cloud using Java

Senaka Fernando Solutions Architect, WSO2 (UK)

Agenda

•  Introduction to Microservices Architecture •  Introduction to WSO2 MSF4J

–  Hands-on Sessions •  Introduction to Kubernetes/Docker •  Demonstrating MSF4J deployment with Kubernetes

–  Demos

Links

• https://github.com/wso2/msf4j/releases/tag/v1.0.0 • https://docs.wso2.com/display/MSF4J100/Running+a

+Basic+Microservice • http://wso2.com/products/data-analytics-server/ • http://wso2.com/products/identity-server/

Microservices Architecture

A method of developing software applications as a suite of independently deployable, small, modular services in which each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal.

Microservices

h"p://mar)nfowler.com/ar)cles/microservices.html6

Inner & Outer Architecture

http://blogs.gartner.com/gary-olliffe/2015/01/30/microservices-guts-on-the-outside/

WSO2 Microservices Framework for Java (MSF4J)

•  Lightweight & fast runtime •  Use Java annotations as a way of defining microservices APIs as well

as metrics •  Support well known & widely used methods such as JAX-RS

annotations •  Provide simple ways to develop & deploy microservices •  Built-in Metrics & Analytics APIs with out-of-the-box integration with

WSO2 Data Analytics Server (DAS) •  To be used in the WSO2 platform as a way of replacing all admin

services as well as defining other microservices for inter-component interactions

MSF4J Implementation

•  Based on the new WSO2 Carbon 5.0 kernel •  Transport is based on Netty 4.0 •  Supports streaming •  High performance •  Very small pack size •  Starts within 300ms •  ~25MB memory consumption for the framework

MSF4J Performance Comparison

MSF4J Memory Consumption Comparison

Core Features of MSF4J

•  Quick & simple development model using simple annotations •  Lightweight & high performance •  Custom interceptors •  OAuth based security •  Metrics gathering & publishing •  Streaming input & streaming output support •  WSO2 DevStudio based tooling for generating microservices projects

starting from a Swagger API definition •  Comprehensive samples demonstrating how to develop microservices

application

MSF4J Flow & Thread Model

Developer Experience & Programming Model

Development Model

•  Maven Archetype •  IDE/Build Classpath (msf4j-all.jar) •  Tooling (Swagger -> Code)

Maven pom.xml

Maven Archetype

mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j -DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0 -DgroupId=org.example -DartifactId=myservice -Dversion=1.0.0-SNAPSHOT -Dpackage=org.example.service

Example - StockQuote Microservice

Application - Main Class

Build and Run !!!

mvn clean install java -jar stockquote-1.0.0.jar

Tooling - WSO2 Developer Studio

Types of Deployment

•  Standalone, Self contained jar files •  OS / Container images

Analytics & Monitoring

Supports annotations •  Timed – measures execution •  Metered – measures rate of events •  Counted – counts the total invocations •  HTTPMonitored – monitors HTTP requests

Analytics & Monitoring

Service Metrics - Console Output

Security

•  Security is done via a central server issuing JWT or OAuth tokens.

•  The OAuth2SecurityInterceptor verifies the token before accessing the resources.

MSF4J Hands-on Sessions

Hello World!

•  Build the sample - wso2msf4j-dist-1.0.0/samples/helloworld

mvn clean install •  Run the sample

java -jar helloworld-*.jar •  Test the sample

curl http://localhost:8080/hello/wso2

Fat JAR samples

•  Refer the sample - https://docs.wso2.com/display/MSF4J100/Developing+a+Microservice+in+Fat+JAR+Mode

Download WSO2 Data Analytics Server

•  http://wso2.com/products/data-analytics-server

HTTP Monitoring with Data Analytics

•  Refer the sample - https://docs.wso2.com/display/MSF4J100/Using+Metrics+and+HTTP+Monitoring+Interceptors

Simple File Server

•  Refer the sample - https://docs.wso2.com/display/MSF4J100/Handling+Files

Download WSO2 Identity Server

•  http://wso2.com/products/identity-server

Security for Microservices

•  Refer the sample - https://docs.wso2.com/display/MSF4J100/Securing+Microservices

Your First MS - Maven Build

mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j -DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0

Your First MS - Write a StudentService

•  API - –  GET /student/getAll - get all students –  GET /student/get/{id} - get student with {id} –  POST /add - add a student

•  Intercept requests •  Monitoring

Your First MS - Annotations

•  JAX-RS HTTP resource methods - @GET @POST @PUT @DELETE

•  Content-negotiation - @Produces @Consumes •  Service lifecycle - @PreDestroy @PostDestroy

Production Deployment with Kubernetes and Docker

Virtual Machines vs Containers

What is Docker

•  Container Virtualization •  Build, pack, ship and run applications as containers •  Build once, run in many places •  Isolated

Docker Filesystem

StockQuote Service Dockerfile

Kubernetes

•  Kubernetes is an open source orchestration system for Docker containers

•  Docker -> Container lifecycle management •  Kubernetes -> Orchestration and container cluster

management

“Kubernetes, I need 5 Tomcat and one MySQL server running at all times.”

Kubernetes in a Nutshell

Kubernetes UI

PetStore sample

Petstore sample

Petstore sample

Petstore sample - deployment view

CONTACT US !

Recommended