An introduction about MicroProfile

MicroProfile is a set of APIs based on Jarkata EE that makes us easy to build Java Enterprise applications according to the microservices architecture model. These APIs include:

Image

With:

  • Open Tracing is used to track the flow of a request to services.
  • Open API is used to create API documentation, we often call it Swagger. You can see about Swagger in Spring Boot.
  • Rest Client is used to calling a RESTful Web Service, similar to RestTemplate or WebClient in Spring.
  • Config is used to do things related to the configuration of the application.
  • Fault Tolerance is used to handle cases where the application is failing.
  • Metrics are used to define application metrics.
  • JWT Propagation is used to work with access tokens in OAuth2 and OpenId Connect.
  • Health exposes runtime information of services.
  • Jakarta EE’s CDI: supports dependency injection in the application.
  • JSON-P (JSON Processing) is used to convert Java object POJO to JSON.
  • JAX-RS implements RESTful Web Service.
  • JSON-B (JSON Binding) is used to convert JSON to Java objects.
  • Jakarta Annotation by Jakarta EE defines a set of annotations for working with Jakarta EE applications.

We can use the MicroProfile Starter tool to create a new MicroProfile project, similar to the Spring framework, at https://start.microprofile.io/:

Image

As an example for this tutorial, I will create a new service using MicroProfile as follows:

Image

You don’t need to select APIs! By default, all MicroProfile APIs are declared in the application.

Click DOWNLOAD to download the project to your computer, then import it with the Maven project into the IDE you are using!

Its results are as follows:

Image

Check out this Maven project’s External Libraries:

Image

you will see in addition to the dependencies of MicroProfile, we also see dependencies of Jakarta EE. They are all APIs, there is no implementation, so to run the MicroProfile application, we must use server runtimes that support MicroProfile such as Open Liberty, Payara, WildFly,… !

I chose to use Open Liberty with the Liberty Maven plugin to run the example for this tutorial as follows:

Image

The contents of the generated server.xml file are as follows:

As you can see, feature microProfile-4.0 is declared for use in the <featureManager> tag. There are also several other configurations. Properties such as project.name, jwt.issuer, app.context.root are declared in the <bootstrapProperties> tag of the Liberty Maven plugin in the pom.xml file.

Running the project with the Liberty Maven plugin, you can access the generated project’s default endpoint http://localhost:9080/data/hello, the results are as follows:

Image

In addition, with the microProfile-4.0 feature declared to support, we can also access some other endpoints such as:

OpenAPI to see API documentation http://localhost:9080/openapi/ui/:

Image

Health check service http://localhost:9080/health/:

Image

Metrics http://localhost:9080/metrics/:

Image

Depending on your needs, please use MicroProfile accordingly!

Add Comment