This repository contains the MicroProfile implementation of the Customer Service which is a part of 'IBM Cloud Native Reference Architecture' suite, available here.
This project is built to demonstrate how to build Customer Microservices applications using Microprofile. This application provides basic operations of creating and querying customer profiles from Apache's CouchDB NoSQL database as part of the Customer Profile function of BlueCompute. Additionally the Auth Microservice calls this microservice to perform Customer username/password authentication.
- Based on MicroProfile.
- OAuth protect the microservice REST API using JWT token signed with a HS256 shared secret.
- Persist Customer data in an Apache's CouchDB NoSQL database using the official Cloudant Java library.
- Deployment options for Minikube environment and ICP.
The Customer Microservice serves 'IBM Cloud Native Reference Architecture' suite, available at https://github.com/ibm-cloud-architecture/refarch-cloudnative-kubernetes, Microservice-based reference application. Though it is a part of a bigger application, Customer service is itself an application in turn that queries the CouchDB Database.
GET /customer/rest/customer # Returns customer using provided JWT
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 Fault Tolerance - This feature helps us to build faulttolerance microservices. In some situations, there may be some impact on the system and it may fail due to several reasons. To avoid such failures, we can design fault tolerant microservices using this feature.
In our sample application, we used @Timeout, @Retry and @Fallback.
- 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 Rest Client - This feature helps us to define typesafe rest clients. These are defined as Java interfaces. The available RESTful apis in our sample application are invoked in a type safe manner.
-
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, @Operation and @Parameter 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 Microprofile metrics with Prometheus.
- MicroProfile OpenTracing - This feature enables distributed tracing. It helps us to analyze the transcation 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 app locally and test the individual service, please follow the instructions provided here.