The sparking fame of the Spring Boot framework in the Java ecosystem dims the mighty but tiny microservice frameworks out there. There is no doubt that the Spring Boot is a well-known all-rounder. However, this article explains a lightweight microservice framework from the company named WSO2. As a former employee of WSO2, I can guarantee their expertise in different service-oriented solutions. The founder of WSO2: Sanjiva Weerawarana is a key contributor to Apache SOAP and Axis2 projects and his passion for web services also reflects on MSF4J.
Requirements
- Java Development Kit
- IntelliJ Idea Community/Ultimate or Eclipse with Maven Support
- Apache Maven (Not necessary if you are not going to build the project outside of the IDE)
Create a New Hello World Project
Step 1:
Create a new Maven project in IntelliJ Idea with the group id: com.javahelps.helloworld and artifact id: msf4j-hello-world.
Step 2:
Add the following dependencies and repositories to the pom.xml file. Prior to Java 9, the MSF4J core jar itself was enough because until Java 8 some of the Java EE packages were part of Java SE. From Java 9, Java EE packages were stripped from the standard edition. Therefore the JAXB API binding dependency is required to run MSF4J if you are using Java 9 or later.
After adding the dependencies, the pom.xml should look like this:
Not all newer versions of libraries guarantee backward compatibility with previous versions. Therefore, I recommend using the same version of the library as in the following pom.xml for your first run. Once you get the code working, search for the artifact ids in the public Maven Repository and use the latest version of the dependencies in your production code. Please note that older versions may have unpatched vulnerabilities and make your code vulnerable to attacks. I will try my best to keep the articles up to date but it is impossible for me to keep track of all libraries used in Java Helps. If you find any breaking changes in newer versions, please comment below.
Implement an MSF4J Service
Step 1:
Create a new class named HelloService.java with the following code. I hope the code is self-explanatory.
Step 2:
Create a MicroservicesRunner and deploy the HelloService in the main method of the Main class as shown below.
Run the MSF4J Service
After saving all the changes run the Main class from IntelliJ IDEA. By default, the web service will run on port 9090.
Using the Postman or CURL, send an HTTP request to any of the endpoints defined in the HelloService class. The following CURL command sends an HTTP GET request to the service.
I hope you find MSF4J simple enough and lightweight for your needs. Still, Spring Boot has its advantages due to the large community behind it and the unlimited list of features. For long-term projects, choosing a framework backed by a large community with frequent bug/security fixes is important. However, if you are looking for lightweight alternatives to Spring Boot for a valid reason, MSF4J is definitely something worth considering.
You can download the complete source code of this project along with all the resources from our Git Hub repository.
If you find this article useful, please share your thoughts below. If you have any questions or issues with getting MSF4J working, you can ask your questions in the comments. Java Helps community will try our best to answer your questions.