![Page 1: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/1.jpg)
Introduction to WSO2 Microservices Framework for Java
Sagara Gunathunga
Software ArchitectWSO2
[email protected] | @sagaras
![Page 2: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/2.jpg)
• Test• Test
2
![Page 3: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/3.jpg)
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
![Page 4: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/4.jpg)
4
What is WSO2 MSF4J?
A lightweight, high performance framework for building Microservices in Java
![Page 5: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/5.jpg)
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
![Page 6: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/6.jpg)
MSF4J- Performance Comparison
![Page 7: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/7.jpg)
MSF4J- Memory Consumption Comparison
![Page 8: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/8.jpg)
MSF4J Implementation• Transport is based on Netty 4.0
• Supports streaming
• High performance
• Low memory footprint
• Starts within 300ms
![Page 9: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/9.jpg)
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 sampleso https://github.com/wso2/msf4j/tree/v1.0.0/samples
![Page 10: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/10.jpg)
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
![Page 11: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/11.jpg)
Security• Security is done via a central server issuing JWT tokens
• The JWTSecurityInterceptor verifies the signature, expiry & claims in the token
![Page 12: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/12.jpg)
Analytics & Monitoring
• Supports annotations• Timed – measures execution time• Metered – measures rate of events• Counted – Counts the total invocations
![Page 13: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/13.jpg)
Analytics & Monitoring
![Page 14: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/14.jpg)
Analytics & Monitoring
![Page 15: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/15.jpg)
Tooling (Swagger -> Code)
Swagger API Definition
MSS Code
1
2
3
![Page 16: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/16.jpg)
MSF4J in Action!
https://github.com/sagara-gunathunga/msf4j-intro-webinar-samples
![Page 17: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/17.jpg)
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
![Page 18: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/18.jpg)
1. Helloworld MSF4J
@Path("/hello")public class HelloWorld {
@GET @Path("/{user}") public String hello(@PathParam("user") String user) {
return "Hello " + user;
}
}
![Page 19: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/19.jpg)
1. Helloworld MSF4J
public class Application {
public static void main(String[] args) {
new MicroservicesRunner() .deploy(new HelloWorld()) .start();
}}
![Page 20: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/20.jpg)
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){ …........................................... ............................................... }}
![Page 21: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/21.jpg)
2. MSF4J Interceptors
public class Application {
public static void main(String[] args) {
new MicroservicesRunner() .deploy(new HelloWorld()) .addInterceptor(new BasicAuthInterceptor ()) .start();
}}
![Page 22: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/22.jpg)
3. MSF4J Metrics
@Path("/hello")public class HelloWorld {
@GET @Path("/{user}") @Metered public String hello(@PathParam("user") String user) {
return "Hello " + user;
}
}
![Page 23: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/23.jpg)
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();
}}
![Page 24: An Introduction to WSO2 Microservices Framework for Java](https://reader035.vdocuments.us/reader035/viewer/2022070523/58ec9b7d1a28abfb748b4685/html5/thumbnails/24.jpg)
4. MSF4J JPA Sample
Database
Hibernate persistence
JPA API
User DAO
User Resource