This document provides an overview of developing microservices for the cloud using Java. It introduces microservices architecture and the WSO2 Microservices Framework for Java (MSF4J). It demonstrates how to develop a simple stock quote microservice using MSF4J annotations and deploy it in standalone and containerized modes. It also covers integrating microservices with Kubernetes and Docker for production deployments in the cloud. Hands-on code samples are provided to illustrate key concepts.
4. 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.
7. 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
8. 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
11. 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
26. Security
• Security is done via a central server issuing JWT or
OAuth tokens.
• The OAuth2SecurityInterceptor verifies the token
before accessing the resources.
35. Your First MS - Maven Build
mvn archetype:generate -
DarchetypeGroupId=org.wso2.msf4j -
DarchetypeArtifactId=msf4j-microservice
-DarchetypeVersion=1.0.0
36. 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
37. Your First MS - Annotations
• JAX-RS HTTP resource methods - @GET @POST
@PUT @DELETE
• Content-negotiation - @Produces @Consumes
• Service lifecycle - @PreDestroy
@PostDestroy
43. 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.”