Introduction to WSO2
Microservices Framework for Java
Sagara Gunathunga
Software Architect
WSO2
sagara@wso2.com | @sagaras
• Test
• Test
2
Previous webinars
• http://wso2.com/library/webinars/2016/01/a-pragmatic-approach-to-
microservice-architecture-the-role-of-middleware/
• http://wso2.com/library/webinars/2016/02/deep-dive-into-microservice-inner-
architecture/
• http://wso2.com/library/webinars/2016/02/deep-dive-into-microservice-outer-
architecture/
3
4
What is WSO2 MSF4J?
A lightweight, high performance framework for
building Microservices in Java
Vision for 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 subset of JAX-
RS & JSR 250 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)
• Built-in security with out of the box integration with WSO2 IS
MSF4J- Performance Comparison
MSF4J- Memory Consumption Comparison
MSF4J Implementation
• Transport is based on Netty 4.0
• Supports streaming
• High performance
• Low memory footprint
• Starts within 300ms
Download
o MSS 1.0.0 release is available at
https://github.com/wso2/msf4j/releases/tag/v1.0.0
o Refer to the getting started guide in GitHub
o A good place to start is the samples
o https://github.com/wso2/msf4j/tree/v1.0.0/samples
Core Features
• Quick & simple development model using simple annotations
• Interceptor API for message interception
• JWT based security context propagation
•
• Metrics gathering & publishing – Console, JMX, WSO2 DAS
• WSO2 DevStudio based tooling for generating microservices projects starting from a
Swagger API definition
• Comprehensive samples demonstrating how to develop Microservices application
• Kubernetes and Docker based reference archeterure and reference application
Security
• Security is done via a central server issuing JWT tokens
• The JWTSecurityInterceptor verifies the signature, expiry & claims in
the token
Analytics & Monitoring
• Supports annotations
• Timed – measures execution time
• Metered – measures rate of events
• Counted – Counts the total invocations
Analytics & Monitoring
Analytics & Monitoring
Tooling (Swagger -> Code)
Swagger API
Definition
MSS
Code
1
2
3
MSF4J in Action!
https://github.com/sagara-gunathunga/msf4j-intro-webinar-samples
1. Helloworld MSF4J
mvn archetype:generate -Dfilter=org.wso2.msf4j:msf4j-microservice
OR
mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j 
-DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0 
-DgroupId=org.wso2.webinar.samples.msf4j -DartifactId=Hello -Dversion=1.0.0-SNAPSHOT 
-Dpackage=org.wso2.webinar.samples.msf4j -DserviceClass=Hello
1. Helloworld MSF4J
@Path("/hello")
public class HelloWorld {
@GET
@Path("/{user}")
public String hello(@PathParam("user") String user) {
return "Hello " + user;
}
}
1. Helloworld MSF4J
public class Application {
public static void main(String[] args) {
new MicroservicesRunner()
.deploy(new HelloWorld())
.start();
}
}
2. MSF4J Interceptors
public class BasicAuthInterceptor implements Interceptor {
@Override
public boolean preCall(HttpRequest request, HttpResponder responder,
ServiceMethodInfo serviceMethodInfo){
…...........................................
...............................................
}
@Override
public void postCall(HttpRequest request, HttpResponseStatus status,
ServiceMethodInfo serviceMethodInfo){
…...........................................
...............................................
}
}
2. MSF4J Interceptors
public class Application {
public static void main(String[] args) {
new MicroservicesRunner()
.deploy(new HelloWorld())
.addInterceptor(new BasicAuthInterceptor ())
.start();
}
}
3. MSF4J Metrics
@Path("/hello")
public class HelloWorld {
@GET
@Path("/{user}")
@Metered
public String hello(@PathParam("user") String user) {
return "Hello " + user;
}
}
3. MSF4J Metrics
public class Application {
public static void main(String[] args) {
new MicroservicesRunner()
.deploy(new HelloWorld())
.addInterceptor(new MetricsInterceptor().init(MetricReporter.CONSOLE,
MetricReporter.JMX))
.start();
}
}
4. MSF4J JPA Sample
Database
Hibernate persistence
JPA API
User DAO
User Resource
CONTACT US !

An Introduction to WSO2 Microservices Framework for Java

  • 1.
    Introduction to WSO2 MicroservicesFramework for Java Sagara Gunathunga Software Architect WSO2 sagara@wso2.com | @sagaras
  • 2.
  • 3.
    Previous webinars • http://wso2.com/library/webinars/2016/01/a-pragmatic-approach-to- microservice-architecture-the-role-of-middleware/ •http://wso2.com/library/webinars/2016/02/deep-dive-into-microservice-inner- architecture/ • http://wso2.com/library/webinars/2016/02/deep-dive-into-microservice-outer- architecture/ 3
  • 4.
    4 What is WSO2MSF4J? A lightweight, high performance framework for building Microservices in Java
  • 5.
    Vision for 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 subset of JAX- RS & JSR 250 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) • Built-in security with out of the box integration with WSO2 IS
  • 6.
  • 7.
  • 8.
    MSF4J Implementation • Transportis based on Netty 4.0 • Supports streaming • High performance • Low memory footprint • Starts within 300ms
  • 9.
    Download o MSS 1.0.0release is available at https://github.com/wso2/msf4j/releases/tag/v1.0.0 o Refer to the getting started guide in GitHub o A good place to start is the samples o https://github.com/wso2/msf4j/tree/v1.0.0/samples
  • 10.
    Core Features • Quick& simple development model using simple annotations • Interceptor API for message interception • JWT based security context propagation • • Metrics gathering & publishing – Console, JMX, WSO2 DAS • WSO2 DevStudio based tooling for generating microservices projects starting from a Swagger API definition • Comprehensive samples demonstrating how to develop Microservices application • Kubernetes and Docker based reference archeterure and reference application
  • 11.
    Security • Security isdone via a central server issuing JWT tokens • The JWTSecurityInterceptor verifies the signature, expiry & claims in the token
  • 12.
    Analytics & Monitoring •Supports annotations • Timed – measures execution time • Metered – measures rate of events • Counted – Counts the total invocations
  • 13.
  • 14.
  • 15.
    Tooling (Swagger ->Code) Swagger API Definition MSS Code 1 2 3
  • 16.
  • 17.
    1. Helloworld MSF4J mvnarchetype:generate -Dfilter=org.wso2.msf4j:msf4j-microservice OR mvn archetype:generate -DarchetypeGroupId=org.wso2.msf4j -DarchetypeArtifactId=msf4j-microservice -DarchetypeVersion=1.0.0 -DgroupId=org.wso2.webinar.samples.msf4j -DartifactId=Hello -Dversion=1.0.0-SNAPSHOT -Dpackage=org.wso2.webinar.samples.msf4j -DserviceClass=Hello
  • 18.
    1. Helloworld MSF4J @Path("/hello") publicclass HelloWorld { @GET @Path("/{user}") public String hello(@PathParam("user") String user) { return "Hello " + user; } }
  • 19.
    1. Helloworld MSF4J publicclass Application { public static void main(String[] args) { new MicroservicesRunner() .deploy(new HelloWorld()) .start(); } }
  • 20.
    2. MSF4J Interceptors publicclass BasicAuthInterceptor implements Interceptor { @Override public boolean preCall(HttpRequest request, HttpResponder responder, ServiceMethodInfo serviceMethodInfo){ …........................................... ............................................... } @Override public void postCall(HttpRequest request, HttpResponseStatus status, ServiceMethodInfo serviceMethodInfo){ …........................................... ............................................... } }
  • 21.
    2. MSF4J Interceptors publicclass Application { public static void main(String[] args) { new MicroservicesRunner() .deploy(new HelloWorld()) .addInterceptor(new BasicAuthInterceptor ()) .start(); } }
  • 22.
    3. MSF4J Metrics @Path("/hello") publicclass HelloWorld { @GET @Path("/{user}") @Metered public String hello(@PathParam("user") String user) { return "Hello " + user; } }
  • 23.
    3. MSF4J Metrics publicclass Application { public static void main(String[] args) { new MicroservicesRunner() .deploy(new HelloWorld()) .addInterceptor(new MetricsInterceptor().init(MetricReporter.CONSOLE, MetricReporter.JMX)) .start(); } }
  • 24.
    4. MSF4J JPASample Database Hibernate persistence JPA API User DAO User Resource
  • 25.