Building Services with WSO2 Microservices framework for Java and WSO2 AS

2,617 views

Published on

In this WSO2Con tutorial session, we go through how to create microservices with the WSO2 MSF4J library, and how to create web services with WSO2 Application Server.

Published in: Software
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,617
On SlideShare
0
From Embeds
0
Number of Embeds
1,574
Actions
Shares
0
Downloads
41
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Building Services with WSO2 Microservices framework for Java and WSO2 AS

  1. 1. Building Services with WSO2 Microservices Framework for Java and WSO2 Application Server Kasun Gajasinghe & Kishanthan Thangarajah WSO2
  2. 2. Agenda • Introduction to Microservices Architecture • Introduction to WSO2 MSF4J – Hands-on Sessions • Introduction to Kubernetes/Docker • Demonstrating MSF4J deployment with Kubernetes • Introduction to WSO2 Application Server – Hands-on Session
  3. 3. 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.
  4. 4. Microservices http://martinfowler.com/articles/microservices.html
  5. 5. Inner & Outer Architecture http://blogs.gartner.com/gary-olliffe/2015/01/30/microservices-guts-on-the-outside/
  6. 6. 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
  7. 7. MSF4J Implementation • Based on the new WSO2 Carbon 5.0 kernel • Transport is based on Netty 4.0 • Supports streaming • High performance • 5MB pack size • Starts within 300ms • ~25MB memory consumption for the framework
  8. 8. MSF4J Performance Comparison
  9. 9. MSF4J Memory Consumption Comparison
  10. 10. 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
  11. 11. MSF4J Flow & Thread Model
  12. 12. Developer Experience & Programming Model
  13. 13. Development Model • Maven Archetype • IDE/Build Classpath (msf4j-all.jar) • Tooling (Swagger -> Code)
  14. 14. Maven pom.xml
  15. 15. 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
  16. 16. Example - StockQuote Microservice
  17. 17. Application - Main Class
  18. 18. Build and Run !!! mvn clean install java -jar stockquote-1.0.0.jar
  19. 19. Tooling - WSO2 Developer Studio
  20. 20. Types of Deployment • Standalone, Self contained jar files • OS / Container images
  21. 21. Analytics & Monitoring Supports annotations • Timed – measures execution • Metered – measures rate of events • Counted – counts the total invocations • HTTPMonitored – monitors HTTP requests
  22. 22. Analytics & Monitoring
  23. 23. Service Metrics - Console Output
  24. 24. Security • Security is done via a central server issuing JWT or OAuth tokens. • The OAuth2SecurityInterceptor verifies the token before accessing the resources.
  25. 25. MSF4J Hands-on Sessions
  26. 26. Hello World! 1. Build the sample - wso2msf4j-dist-1.0.0 /samples/helloworld mvn clean install 2. Run the sample java -jar helloworld-*.jar 3. Test the sample curl http://localhost:8080/hello/wso2
  27. 27. Generate a sample with Maven archetype mvn archetype:generate - DarchetypeGroupId=org.wso2.msf4j - DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0
  28. 28. Hands-on - 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
  29. 29. Service class annotations • JAX-RS HTTP resource methods - @GET @POST @PUT @DELETE • Content-negotiation - @Produces @Consumes • Service lifecycle - @PreDestroy @PostDestroy
  30. 30. HTTP Monitoring with Data Analytics Server 1. Refer the sample - wso2msf4j-1.0.0/samples/metrics- httpmon/metrics-httpmon-fatjar
  31. 31. Production Deployment with Kubernetes and Docker
  32. 32. Virtual Machines vs Containers
  33. 33. What is Docker • Container Virtualization • Build, pack, ship and run applications as containers • Build once, run in many places • Isolated
  34. 34. Docker Filesystem
  35. 35. StockQuote Service Dockerfile
  36. 36. 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.”
  37. 37. Kubernetes in a Nutshell
  38. 38. Kubernetes UI
  39. 39. PetStore sample
  40. 40. Petstore sample
  41. 41. Petstore sample
  42. 42. Petstore sample - deployment view
  43. 43. Demo - Petstore
  44. 44. Building Services with WSO2 Application Server
  45. 45. Current status of Application Server • Latest release - AS 5.3.0 • Built on top of WSO2 Carbon • Embedded Apache Tomcat 7 and Apache TomEE 7 • First class support for – JAX-WS and JAX-RS services – JavaEE 6 Web Profile applications
  46. 46. Future plan for Application Server • Upcoming release - AS 6.0 • NOT based on WSO2 Carbon or OSGi! • Built on top of Apache Tomcat
  47. 47. AS 6.0 • HTTP Request Monitoring for Tomcat • Seamless integration with WSO2 Identity Server for SAML SSO Authentication • Classloading improvements Upcoming - Integration with WSO2 API Manager for exposing APIs. (API Everywhere!)
  48. 48. Hands-on Session
  49. 49. Questions?
  50. 50. Thank You

×