developing micro-services for cloud using java

50
Developing Microservices for Cloud using Java Senaka Fernando Solutions Architect, WSO2 (UK)

Upload: wso2-inc

Post on 17-Jan-2017

757 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Developing Micro-Services for Cloud using Java

Developing Microservices for Cloud using Java

Senaka Fernando Solutions Architect, WSO2 (UK)

Page 2: Developing Micro-Services for Cloud using Java

Agenda

•  Introduction to Microservices Architecture •  Introduction to WSO2 MSF4J

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

–  Demos

Page 3: Developing Micro-Services for Cloud using Java

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/

Page 4: Developing Micro-Services for Cloud using Java

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.

Page 5: Developing Micro-Services for Cloud using Java

Microservices

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

Page 6: Developing Micro-Services for Cloud using Java

Inner & Outer Architecture

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

Page 7: Developing Micro-Services for Cloud using Java

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

Page 8: Developing Micro-Services for Cloud using Java

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

Page 9: Developing Micro-Services for Cloud using Java

MSF4J Performance Comparison

Page 10: Developing Micro-Services for Cloud using Java

MSF4J Memory Consumption Comparison

Page 11: Developing Micro-Services for Cloud using Java

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

Page 12: Developing Micro-Services for Cloud using Java

MSF4J Flow & Thread Model

Page 13: Developing Micro-Services for Cloud using Java

Developer Experience & Programming Model

Page 14: Developing Micro-Services for Cloud using Java

Development Model

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

Page 15: Developing Micro-Services for Cloud using Java

Maven pom.xml

Page 16: Developing Micro-Services for Cloud using Java

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

Page 17: Developing Micro-Services for Cloud using Java

Example - StockQuote Microservice

Page 18: Developing Micro-Services for Cloud using Java

Application - Main Class

Page 19: Developing Micro-Services for Cloud using Java

Build and Run !!!

mvn clean install java -jar stockquote-1.0.0.jar

Page 20: Developing Micro-Services for Cloud using Java

Tooling - WSO2 Developer Studio

Page 21: Developing Micro-Services for Cloud using Java

Types of Deployment

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

Page 22: Developing Micro-Services for Cloud using Java

Analytics & Monitoring

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

Page 23: Developing Micro-Services for Cloud using Java

Analytics & Monitoring

Page 24: Developing Micro-Services for Cloud using Java

Service Metrics - Console Output

Page 25: Developing Micro-Services for Cloud using Java
Page 26: Developing Micro-Services for Cloud using Java

Security

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

•  The OAuth2SecurityInterceptor verifies the token before accessing the resources.

Page 27: Developing Micro-Services for Cloud using Java

MSF4J Hands-on Sessions

Page 28: Developing Micro-Services for Cloud using Java

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

Page 29: Developing Micro-Services for Cloud using Java

Fat JAR samples

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

Page 30: Developing Micro-Services for Cloud using Java

Download WSO2 Data Analytics Server

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

Page 31: Developing Micro-Services for Cloud using Java

HTTP Monitoring with Data Analytics

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

Page 32: Developing Micro-Services for Cloud using Java

Simple File Server

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

Page 33: Developing Micro-Services for Cloud using Java

Download WSO2 Identity Server

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

Page 34: Developing Micro-Services for Cloud using Java

Security for Microservices

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

Page 35: Developing Micro-Services for Cloud using Java

Your First MS - Maven Build

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

Page 36: Developing Micro-Services for Cloud using Java

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

Page 37: Developing Micro-Services for Cloud using Java

Your First MS - Annotations

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

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

Page 38: Developing Micro-Services for Cloud using Java

Production Deployment with Kubernetes and Docker

Page 39: Developing Micro-Services for Cloud using Java

Virtual Machines vs Containers

Page 40: Developing Micro-Services for Cloud using Java

What is Docker

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

Page 41: Developing Micro-Services for Cloud using Java

Docker Filesystem

Page 42: Developing Micro-Services for Cloud using Java

StockQuote Service Dockerfile

Page 43: Developing Micro-Services for Cloud using Java

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

Page 44: Developing Micro-Services for Cloud using Java

Kubernetes in a Nutshell

Page 45: Developing Micro-Services for Cloud using Java

Kubernetes UI

Page 46: Developing Micro-Services for Cloud using Java

PetStore sample

Page 47: Developing Micro-Services for Cloud using Java

Petstore sample

Page 48: Developing Micro-Services for Cloud using Java

Petstore sample

Page 49: Developing Micro-Services for Cloud using Java

Petstore sample - deployment view

Page 50: Developing Micro-Services for Cloud using Java

CONTACT US !