What is Microservices?
Microservices are smaller modules of code that address specific business needs. You can combine these services to handle larger projects, even if they were developed in different programming languages. These service clusters are what we call service oriented architecture (SOA).
Most microservices use the Java (MSF4J) microservice framework. You have multiple environments including WSO2, Spring Boot, Jersey, and Swagger. The WSO2 environment is one of the most effective frameworks and open source enterprise integration platform.
What are features?
- Lightweight
- Its pack size is 9MB
- Memory consumption is less than 250 MB
- Quick run time
- It begins within 300 milli seconds
- It runs in docker based containers.
- Simple in development, implementation and monitoring.
- Development is annotation based.
- It is Swagger annotation based.
- It generates swagger definitions.
- Includes monitoring of microservices
- Program mode is Spring native.
- Studio based tool to generate microservices
- Microservices projects start with Swagger API definition.
- Full list of sample programs available
- Demonstrations are available to how to do application
- Closely matching with templates engines ‘Mustache’
- Analytics and metrics generation with DAS analytic server
- Secure
- Web token validation with in-built JASON.
- Authenticates and in-built support for BasicAuth and OAuth2.
- Leverages with WSO2 identity Server
- Third party authentication servers support
- Support through established OAuth2 introspection API
- Custom Interceptors can be developed. This helps to generate additional tokens.
- Scalable and highly available
- High level of performance with Netty 4.0 support HTTP and HTTPs transports.
- Reliable.
- Large messages are supported with native based streaming.
- Developers can have full control of streaming.
MSF4J 2.0 product is from WSO2 for microservices framework for Java in enterprise integration platform.
While we will configure the other WSO2 products for you, you must create the code for WSO2 MSF4J 2.0 yourself. However, you can use the one liner code below as a sample.
Figure -1, Testing sample application
You can find more information on how to configure your build by following the links below.
Application.java
public class Application {
public static void main(String[] args) {
new MicroservicesRunner()
.deploy(new HelloService())
.start();
}
}
Hello Service.java
package org.example.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@Path("/hello")
public class HelloService {
@GET
@Path("/{name}")
public String hello(@PathParam("name") String name) {
return "Hello " + name;
}
}
Build and Run the service
mvn package
Hello-Service-0.1-SNAPSHOT.jar in the target directory
java -jar target/Hello-Service-*.jar
Test the Service with cURL
curl http://localhost:8080/hello/wso2
You should see a response that prints
"Hello wso2"
The WSO2 MSF4J 2.0 programming model is annotation based and open source. It aims to create a container type implementation for creating microservices.
Microservices developed in WSO2 MSF4J 2.0 boot in milliseconds while in the docker container, and be added with docker image definition.
You can develop microservices, exception mappers, and interceptors in the native Spring mode programming model. We call these services Spring Beans, and you can link them at runtime.
WSO2 MSF4J supports JAX-RS annotations, which help to write and monitor microservices. It also supports Swagger annotations to microservices to enrich the swagger definitions.
WSO2 MSF4J 2.0 helps to create new constructs such as Streaming output and Exception mapper. It also supports FormParam and FormDataParam annotations.
WSO2 MSF4J 2.0 offers higher performance than other similar products on the market with fewer resources.
Figure 2, statistical comparison in Performance.
As shown the figure 2, WSO2 MSF4J 2.0 scores with high throughput.
WSO2 MSF4J 2.0 supports the Spring framework as well, which is very popular in java programming. With it, you can create MSF4J services and extensions with features that let you integrate your code with third party frameworks in enterprise integration platform .
Features supported by WSO2 MSF4J 2.0 Spring module:
- Configuration and registration of MSF4J services are available as Spring Beans.
- AOP, JPA support, JDBC support, Dependency Injection features are supported by MSF4J services.
- Configuration and registration of MSF4J interceptors are available as Spring Beans.
- Support to MSF4J ExceptionMapper extensions is available in Spring framework.
- Configuration support to HTTP Post, SSL configurations, inbuilt interceptors are available in MSF4J framework.
- Support environment specific values to MSF4J services in Spring framework.
Development of MSF4J services with Spring framework development in enterprise integration platform, requires that you register your MSF4J annotation web resource class as a Spring bean. After the registration, it will be exposed as MSF4J service. To complete the task, you need to add few more options such as @component, @path, and @autowired annotations.
Instead of annotating the resource class, you can use the Spring application context to register MSF4J services directly. WSO2 supports both Spring based java configuration and traditional XML based configurations.
Interceptors define a set of tasks to be completed before working incoming messages.
You develop and configure your own custom MSF4J interceptors, or one of the many built-in ones.
You can create your own interceptors through the @component annotation or through the Spring ApplicationContext with the Spring Java or XML configurations.
You can develop MSF4J ExceptionMappers with Spring as well. Exception mappers move exceptions handling to middle tier so you can handle them all in one place instead of spread across everywhere
You can define exception mappers with the @component annotation with ExceptionMappers implementation classes, or explicitly through Spring ApplicationContext within the Spring or XML configuration.
You can also configure MSF4J transports in either mode as well.
Figure 3, Equivalent layers mapping
You inject environment specific parameters such as database access details, SSL properties and JMS broker configuration into Spring framework during startup instead of moving them into application code.
We have repository and RESTfull resource classes you can integrate into your application with the dependency injection (DI) feature of the Spring framework. You can use them in both Spring and XML methods by using the @Autowired annotation.
Figure-4, Implementation styles
Repository classes come from the Hybernate Spring module, but you can create resource classes in multiple ways including the Hybernate session object, the Spring Hybernate template, or through the JPA entity manager. More details are provided in these links.
WSO2 MSF4J 2.0 is an exemplary, open source, enterprise integration tool for Java microservices in all possible models and in framework.
Leave a Comment