This document provides an overview of WSO2 MSF4J, a lightweight Java framework for building microservices. It describes MSF4J's annotation-based programming model, support for Spring configuration, serverless execution, streaming, security, monitoring, and compares it to Spring Boot. MSF4J provides a simple way to define microservice APIs, built-in metrics and analytics, fast startup times, and low memory usage.
3. • Container-native microservices framework
• Simple way of defining microservice APIs as well as
metrics
• Provide simple ways to develop and deploy
microservices
• Built-in metrics and analytics APIs with OOB
integration with WSO2 Streaming Analytics
Vision of WSO2 MSF4J
4. WSO2 MSF4J - An Overview
• Simple Java-based programming model with annotations
• Fast boot up - microservices can be booted in a few
milliseconds in a Docker container and can be easily
added to a Docker image
• Secures microservices leveraging JWT, BasicAuth and
OAuth2 and has the capability to integrate with
third-party authentication servers
• Monitors microservices service behavior with analytics
dashboards
5. Implementation of WSO2 MSF4J
• HTTP transport is based on Netty 4.0
• Experimental gRPC support
• Supports streaming
• High performance
• 5MB pack size
• Starts in under 300 ms
• Less than 25 MB memory consumption for the
framework
7. Annotation-based Programming Model
• Supports JAX-RS based annotations
– Class-level annotations
– Method-level annotations
– Parameter-level annotations
– Lifecycle callback method annotations
• Supports Swagger-based annotations
– Enables generating Swagger API definition from a single
API call
– Humans and computers can discover and understand
capabilities of each service
8. Spring-Based Microservices
• Supports a Spring-native development model with
– Dependency Injection (DI)
– Standard configuration annotations (e.g.
@Configuration, @Component, @AutoWired)
• Makes it easy to bring in third-party libraries and wire
them in at runtime
• e.g. those familiar with Spring-JPA can use Spring-JPA
library to integrate the Hibernate ORM framework with
an WSO2 MSF4J service
9. Serverless Execution
• Supports server-less execution with fat JAR
– Fat JAR is a JAR file with all dependencies in one fat
(uber) JAR
– Creating a fat JAR and running it in a Java process is
referred to as serverless execution
– Serverless execution does not involve unzipping a file
and helps to start an app without a shell script
• Supports service lifecycle methods
10. Streaming
• Adopts efficient model to handle Streaming Input (request
messages) and Streaming Output (response messages)
• Streaming Input - HTTP chunked requests can be handled in two
ways:
– Zero-copy method – Each chunk of a request is treated separately
• chunk() method is called when requests arrive
• finished () method is called after the last chunk arrives
• error () method called if an error occurs while processing the request
– Chunk aggregation – Aggregates all chunks of the request and presents it as
a full HTTP request to the resource method
• Streaming Output – Useful when handling large data volumes – no
need to load into memory
11. Custom Interceptors
• Custom interceptors can be used to perform certain
actions before or after a request arrives to resource
methods
• Custom interceptors should implement the
org.wso2.msf4j.Interceptor interface
12. File Handling
• Serve files from the resource methods by returning either of the
following:
– java.io.File
– java.io.InputStream
– javax.ws.rs.core.Response object with a java.io.File
– java.io.InputStream entity
• Streaming is supported by default for java.io.File and
java.io.InputStream entities
• javax.ws.rs.core.StreamingOutput is also supported by WSO2
MSF4J - provides the service author more control over the chunk
size
13. gRPC Support
syntax = "proto3";
...
// The greeting service definition.
service HelloService {
// Sends a greeting
rpc hello (HelloRequest) returns (HelloResponse) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloResponse {
string message = 1;
}
14. Exception Mapper
• Supports JAX-RS ExceptionMapper, which allows the creation of
custom responses when exceptions are thrown from MSF4J services
• The following code segment shows how ExceptionMappers are
registered with the WSO2 MSF4J runtime:
JAX-RS Runtime
Exception
Mapping
Exception
Response
Thrown Exception
HTTP
15. Circuit Breaker
• Nygard's circuit
breaker pattern is
supported in
WSO2 MSF4J
using the Netflix
Hystrix library
Closed
On call: Pass through
Call succeeds: Reset failures count
and throw exception
Threshold reached: Trip breaker
Open
On call: Fail(throw exception)
On timeout: Attempt reset
Half-Open
On call: Pass through
Call succeeds: Reset
Call fails: Trip breaker
Trip breaker
Reset breaker
Trip
breaker
Attempt
reset
16. Security
• Security is done via a central server issuing JWT tokens
• The JWTSecurityInterceptor verifies the signature, expiry
and claims in the token
17. Analytics and Monitoring
• Supports annotations
– Timed – measures execution time
– Metered – measures rate of events
– Counted – counts the total number of invocations
– HTTPMonitored – monitors HTTP requests
33. MSF4J Spring Boot (SB)
Throughput Slightly higher than SB
Latency
Similar at lower concurrencies. MSF4J displays lower latency than Spring
Boot at higher concurrencies.
Default memory
footprint
(on startup) Less than 20MB 180MB
Min memory
requirement 7MB 25MB
Distribution size 6 MB 13MB
Startup time Less than 300ms 3 sec
Built-in analytics Yes No
Built-in Swagger
support Yes No
JAXRS annotation
support Yes No
34. • MSF4J 2.0.0 release is available at
https://github.com/wso2/msf4j/releases/tag/v2.4.2
• Refer to the getting started guide in
http://github.com/wso2/msf4j
• A good place to start is the samples
Download and Get Started!