BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News WSO2 MSF4J Adds Support for Spring and Swagger

WSO2 MSF4J Adds Support for Spring and Swagger

This item in japanese

Lire ce contenu en français

WSO2 MSF4J 2.0 has added support for Spring, Swagger definition generation, ExceptionMapper and StreamingOutput.

WSO2 MSF4J is an open source framework for building microservices in Java. The framework has a small memory footprint at 25MB and starts up in less than 400ms, according to WSO2. The recently released v. 2.0 comes with a number of improvements, including:

  • Support for Spring annotations and runtime. Microservices, interceptors and exception mappers can now be written as Spring beans
  • Generate Swagger definitions and support for Swagger annotations
  • Support for ExceptionMapper which connects an exception thrown by a microservice with an HTTP response
  • Support for StreamingOutput which enables the developer to control how the response is streamed back to the caller

Some of the WSO2 MSF4J main features are:

  • Uses Java annotations for defining microservice APIs
  • Supports JAX-RS and JSR 250 (annotations)
  • Integrated with other WSO2 development, deployment, monitoring and scaling tools
  • Integrated with WSO2 Data Analytics Server
  • Integrated with WSO2 Identity Server
  • It comes with an API Interceptor that catches messages for various reasons such as logging
  • Development through WSO2 DevStudio which can generate a microservices project from a Swagger API definition
  • Message transport is done via Netty
  • Requests can be traced through a unique message ID

To create a microservice with MSF4J, one needs to annotate a Java class to define the API endpoints and deploy it with a runner. A basic HelloWorld example looks like this:

@Path("/hello")
public class HelloService {

    @GET
    @Path("/{name}")
    public String hello(@PathParam("name") String name) {
        return "Hello " + name;
    }
}

and it is deployed with

public class Application {
    public static void main(String[] args) {
        new MicroservicesRunner()
                .deploy(new HelloService())
                .start();
    }
}

As a result, the URL

curl http://localhost:8080/hello/world

will get the response “Hello world”.

Microservices created with WSO2 MSF4J can be built with Maven and deployed in Docker containers.

Rate this Article

Adoption
Style

BT