This repository contains the MicroProfile implementation of the Inventory Service which is a part of 'IBM Cloud Native Reference Architecture' suite, available here
- Introduction
- How it works
- Implementation
- Features
- Deploying the Bluecompute App
- Run Inventory Service locally
- References
This project demonstrates the implementation of Inventory Microservice. The inventory microservice uses MySQL database as its datasource. It has the complete list of items of our store front.
- Based on MicroProfile.
- Uses MySQL as the inventory database.
Inventory Microservice serves 'IBM Cloud Native Reference Architecture' suite, available here, Microservice-based reference application. Though it is a part of a bigger application, Inventory service is itself an application in turn that manages the data from data store. Catalog Microservice serves as the cache to the Inventory.
MicroProfile is an open platform that optimizes the Enterprise Java for microservices architecture. In this application, we are using MicroProfile 1.3. This includes
- MicroProfile 1.0 (JAX-RS 2.0, CDI 1.2, and JSON-P 1.0)
- MicroProfile 1.1
- MicroProfile 1.2 (MicroProfile Fault Tolerance 1.0, MicroProfile Health Check 1.0, MicroProfile JWT Authentication 1.0).
- MicroProfile Config 1.2 (supercedes MicroProfile Config 1.1), MicroProfile Metrics 1.1 (supercedes MicroProfile Metrics 1.0), MicroProfile OpenAPI 1.0, MicroProfile OpenTracing 1.0, MicroProfile Rest Client 1.0.
You can make use of this feature by including this dependency in Maven.
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>1.3</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
You should also include a feature in server.xml.
<server description="Sample Liberty server">
<featureManager>
<feature>microprofile-1.3</feature>
</featureManager>
<httpEndpoint httpPort="${default.http.port}" httpsPort="${default.https.port}"
id="defaultHttpEndpoint" host="*" />
</server>
-
Java SE 8 - Used Java Programming language
-
CDI 1.2 - Used CDI for typesafe dependency injection
-
JAX-RS 2.0 - JAX-RS is used for providing both standard client and server APIs for RESTful communication by MicroProfile applications.
-
Eclipse MicroProfile Config - Configuration data comes from different sources like system properties, system environment variables,
.properties
file etc. These values may change dynamically. Using this feature helps us to pick up configured values immediately after they got changed.
The config values are sorted according to their ordinal. We can override the lower importance values from outside. The config sources by default, below is the order of importance.
- System.getProperties()
- System.getenv()
- all META-INF/microprofile-config.properties files on the ClassPath.
In our sample application, we obtained the configuration programatically.
- MicroProfile Health Check - This feature helps us to determine the status of the service as well as its availability. This helps us to know if the service is healthy. If not, we can know the reasons behind the termination or shutdown.
In our sample application, we injected this /health
endpoint in our liveness probes.
- MicroProfile OpenAPI - This feature helps us to expose the API documentation for the RESTful services. It allows the developers to produce OpenAPI v3 documents for their JAX-RS applications.
In our sample application, we used @OpenAPIDefinition, @Info, @Contact, @License, @APIResponses, @APIResponse, @Content, @Schema and @Operation annotations.
- MicroProfile Metrics - This feature allows us to expose telemetry data. Using this, developers can monitor their services with the help of metrics.
In our sample application, we used @Timed, @Counted and @Metered annotations. These metrics are reused using reuse
functionality. We also integrated them with Prometheus.
- MicroProfile OpenTracing - This feature enables distributed tracing. It helps us to analyze the transaction flow so that the we can easily debug the problematic services and fix them. It enables and allows for custom tracing of JAX-RS and non-JAX-RS methods.
In our sample application, we used Zipkin as our distributed tracing system. We used @Traced and an ActiveSpan object to retrieve messages.
To build and run the entire BlueCompute demo application, each MicroService must be spun up together. This is due to how we set up our Helm charts structure and how we dynamically produce our endpoints and URLs.
Further instructions are provided here.
To deploy it on IBM Cloud Private, please follow the instructions provided here.
To deploy it on Minikube, please follow the instructions provided here.
To deploy the Inventory locally using Maven or Helm and test the individual service, please follow the instructions provided here.