1
Microprofile
Specs from 1.0 to 5.0
rbenevides@microsoft.com
Link
rafabene@gmail.com
@rafabene
apiVersion: microsoft/v1
kind: CloudSolutionArchitect
metadata:
name: Rafael Benevides
namespace: Azure Customer Success
annotations:
apache/contributor: Apache DeltaSpike PMC
labels:
developer: Java, NodeJS
hobby: 4x4, drones
spec:
replicas: 1
containers:
image: benevides/rafael:latest
Rafael Benevides
What is Eclipse Microprofile?
@rafabene - http://bit.ly/slides-microprofile
Community - individuals, organizations, vendors
@rafabene - http://bit.ly/slides-microprofile
Current MicroProfile Implementations
5
@rafabene - http://bit.ly/slides-microprofile
MicroProfile 1.0 (Sep, 2016)
MicroProfile 1.0
JAX-RS 2.0
JSON-P 1.0
CDI 1.2
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 1.1 (Aug, 2017)
MicroProfile 1.1
= New
= No change from last release
JAX-RS 2.0
JSON-P 1.0
CDI 1.2
Config 1.0
@rafabene - http://bit.ly/slides-microprofile
Configuration
Applications need to be configured based on a running environment. It must be possible to modify configuration data from outside an application so that the application itself does not need to be repackaged
Dev
Test
Prod
@rafabene - http://bit.ly/slides-microprofile
Configuration
By default there are 3 default config sources:
@Inject
@ConfigProperty(name = "preference.api.url",
defaultValue = "http://localhost:8180/")
private String preferenceURL;
@rafabene - http://bit.ly/slides-microprofile
Configuration
CDI
CDI
11
Configuration
getPropertyNames()
getConfigSources()
getValue(...)
@rafabene
Eclipse MicroProfile 1.2 (Sep, 2017)
MicroProfile 1.2
= Updated
= No change from last release
JAX-RS 2.0
JSON-P 1.0
CDI 1.2
Config 1.1
Fault�Tolerance 1.0
JWT�Propagation 1.0
Health�Check 1.0
Metrics 1.0
= New
@rafabene - http://bit.ly/slides-microprofile
Health Check 1.0
Health checks are used to probe the state of a computing node from another machine (i.e. kubernetes service controller) with the primary target being cloud infrastructure environments where automated processes maintain the state of computing nodes
@rafabene - http://bit.ly/slides-microprofile
Health Check 1.0 - Goals
@rafabene - http://bit.ly/slides-microprofile
Health Check (Outcomes and Checks)
@Liveness
@ApplicationScoped
public class UserAvailabilityHealthCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
HealthCheckResponseBuilder response = HealthCheckResponse.named("usersAvailable");
try {
// Try users microservices
return response.up().build();
} catch (Exception ex) {
return response.down().build();
}
}
}
@rafabene - http://bit.ly/slides-microprofile
Health Check 1.0 (Outcomes and Checks)
@Health
@ApplicationScoped
public class SubscribersListFullCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
HealthCheckResponseBuilder response =
HealthCheckResponse.named("subscribersListFull");
try {
// Try users microservices
response.withData("Number of subscribers",
numberOfSubscribers)
return response.up().build();
} catch (Exception ex) {
return response.down().build();
}
}
}
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0
To ensure reliable operation of software it is necessary to monitor essential system parameters. Metrics adds well-known monitoring endpoints and metrics for each process
Metric Registry
Required Base metrics
Application metrics
Vendor-specific metrics
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0 - Goals
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0 - Difference to health checks
Metrics can also help those scheduling systems decide when to scale the application to run on more or fewer machines.
Health Check | Metric |
YES/NO Response | long term trend data for capacity planning |
"Is my application still running ok?" | pro-active discovery of issues (e.g. disk usage growing without bounds |
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0 - Goals
General
Thread
ClassLoading
Operating System
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0 - Goals
The following three sets of sub-resource (scopes) are exposed.
• base: metrics that all MicroProfile vendors have to provide
• vendor: vendor specific metrics (optional)
• application: application-specific metrics (optional)
http://localhost:8080/metrics/base
http://localhost:8080/metrics/vendor
http://localhost:8082/metrics/application
@rafabene - http://bit.ly/slides-microprofile
Metrics 1.0 - API
The easiest way is to annotate field, method or class with an annotation.
Annotation | Description | Default Unit |
@Counted | Denotes a counter, which counts the invocations of the annotated object. | MetricUnits.NONE |
@Gauge | Denotes a gauge, which samples the value of the annotated object. | none Must be supplied by the user |
@Metered | Denotes a meter, which tracks the frequency of invocations of the annotated object. | MetricUnits.PER_SECOND |
@Metric | An annotation that contains the metadata information when requesting a metric to be injected or produced | MetricUnits.NONE |
@Timed | Denotes a timer, which tracks duration of the annotated object. | MetricUnits.NANOSECONDS |
@rafabene - http://bit.ly/slides-microprofile
Fault Tolerance 1.0
Fault tolerance is about leveraging different strategies to guide the execution and result of some logic. Retry policies, bulkheads, and circuit breakers are popular concepts in this area. They dictate whether and when executions should take place, and fallbacks offer an alternative result when an execution does not complete successfully
@rafabene - http://bit.ly/slides-microprofile
Fault Tolerance 1.0
@Timeout
@Retry
@Fallback
@Bulkhead
@CircuitBreaker
@rafabene - http://bit.ly/slides-microprofile
Fault Tolerance 1.0
@Fallback(fallbackMethod = "defaultAuthor")
@Retry(maxRetries = 5)
@CircuitBreaker(requestVolumeThreshold = 10,
failureRatio = 0.6,
delay = 2000L,
successThreshold = 2)
@Timeout(800)
public JsonObject findAuthorByEmail(String email) {
// Call remote service
}
public JsonObject defaultAuthor(String email) {
return Json.createObjectBuilder()
.add("firstName", "")
.add("lastName", "Unkown")
.add("bio", "Try again later")
.add("email", email)
.build();
}
@rafabene - http://bit.ly/slides-microprofile
JWT Propagation
The security requirements that involve microservice architectures are strongly related with RESTful Security. In a RESTful architecture style, services are usually stateless and any security state associated with a client is sent to the target service on every request in order to allow services to re-create a security context for the caller and perform both authentication and authorization checks
@rafabene - http://bit.ly/slides-microprofile
What is JWT?
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object
A client sends a HTTP request to Service A including the JWT as a bearer token:
@rafabene - http://bit.ly/slides-microprofile
What is JWT?
@rafabene - http://bit.ly/slides-microprofile
JWT Usage
JAX-RS & OpenAPI
Eclipse MicroProfile 1.3 (Jan, 2018)
MicroProfile 1.3
JAX-RS 2.0
JSON-P 1.0
CDI 1.2
Config 1.2
Fault�Tolerance 1.0
JWT�Propagation 1.0
Health�Check 1.0
Metrics 1.1
Open Tracing 1.0
Open API 1.0
= Updated
= No change from last release
= New
Rest Client 1.0
@rafabene - http://bit.ly/slides-microprofile
OpenAPI 1.0
Management of microservices in an MSA can become unwieldy as the number of microservices increases. Microservices can be managed via their APIs. Management, security, load balancing, and throttling are policies that can be applied to APIs fronting microservices. OpenAPI provides Java interfaces and programming models which allow Java developers to natively produce OpenAPI v3 documents from their JAX-RS applications.
@rafabene - http://bit.ly/slides-microprofile
OpenAPI 1.0
@rafabene - http://bit.ly/slides-microprofile
SECTION
OpenAPI
@rafabene
Open API
33
@rafabene - http://bit.ly/slides-microprofile
REST Client 1.0
In the Microservices world, we typically talk REST to other services. While the JAX-RS specification defines a fluent API for making calls, it is difficult to make it a true type safe client. Several JAX-RS implementations support the ability to take an interface definition and create a JAX-RS client from it (JBoss RestEasy, Apache CXF) as well as being supported by a number of service providers (Wildfly Swarm, OpenFeign). MicroProfile Rest Client API provides a type-safe approach to invoke RESTful services over HTTP in a consistent and easy-to-reuse fashion.
@rafabene - http://bit.ly/slides-microprofile
REST Client
String apiUrl = "http://localhost:9080/movieReviewService";�MovieReviewService reviewSvc = � RestClientBuilder.newBuilder()� .baseUrl(apiUrl)� .build(MovieReviewService.class);��Review review = new Review(3 /*stars*/,"Good Movie.");��reviewSvc.submitReview( movieId, review );
@rafabene - http://bit.ly/slides-microprofile
OpenTracing 1.0
Tracing the flow of a request in a distributed environment has always been challenging but it is even more complex in a microservices architecture, where requests traverse across not just architectural tiers but also multiple services. The MicroProfile OpenTracing API provides a standard for instrumenting microservices for distributed tracing.
@rafabene - http://bit.ly/slides-microprofile
37
Open tracing
Open Tracing - Jaeger
Eclipse MicroProfile 1.4 (Jun, 2018)
MicroProfile 1.4
JAX-RS 2.0
JSON-P 1.0
CDI 1.2
Config 1.3
Fault�Tolerance 1.1
JWT�Propagation 1.1
Health�Check 1.0
Metrics 1.1
Open Tracing 1.1
Open API 1.0
= Updated
= No change from last release
= New
Rest Client 1.1
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 2.0 (Jun, 2018)
MicroProfile 2.0
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 1.1
JWT�Propagation 1.1
Health�Check 1.0
Metrics 1.1
Open Tracing 1.1
Open API 1.0
= Updated
= No change from last release (MicroProfile 1.4)
= New
Rest Client 1.1
JSON-B 1.0
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 2.0 - Goals
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 2.1 (Oct, 2018)
= Updated
= No change from last release (MicroProfile 2.0)
= New
MicroProfile 2.1
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 1.1
JWT�Propagation 1.1
Health�Check 1.0
Metrics 1.1
Open Tracing 1.2
Open API 1.0
Rest Client 1.1
JSON-B 1.0
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
JSON-B 1.0
= Java EE / Jakarta EE
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 2.2 (Feb, 2019)
MicroProfile 2.2
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 2.0
JWT�Propagation 1.1
Health�Check 1.0
Metrics 1.1
Open Tracing 1.3
Open API 1.1
= Updated
= No change from last release (MicroProfile 2.1)
= New
Rest Client 1.2
JSON-B 1.0
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
JSON-B 1.0
= Java EE / Jakarta EE
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 3.0 (Jun 2019)
https://github.com/eclipse/microprofile/releases/download/3.0/microprofile-spec-3.0.pdf
MicroProfile 3.0
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 2.0
JWT�Propagation 1.1
Health�Check 2.0
Metrics 2.0
Open Tracing 1.3
Open API 1.1
= Updated
= No change from last release (MicroProfile 2.2)
= New
Rest Client 1.3
JSON-B 1.0
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
JSON-B 1.0
= Java EE / Jakarta EE
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 3.1 (Oct 2019)
MicroProfile 3.1
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 2.0
JWT�Propagation 1.1
Health 2.1
Metrics 2.1
Open Tracing 1.3
Open API 1.1
= Updated
= No change from last release (MicroProfile 3.0)
= New
Rest Client 1.3
JSON-B 1.0
Standalone
Context Propagation 1.0
Reactive Streams Operators 1.0
Outside umbrella
Reactive Messaging 1.0
@rafabene - http://bit.ly/slides-microprofile
MicroProfile Reactive Capabilities
MicroProfile Reactive Streams Operators
A set of operators to create new reactive streams, process the transiting data and consume them with ease
MicroProfile Reactive Messaging
Defines a development model for declaring CDI beans producing, consuming and processing messages. It relies on Reactive Streams Operators and CDI
MicroProfile Context Propagation
APIs for propagating contexts across units of work that are thread-agnostic
47
Check it out and send us your feedback!
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 3.2 (Nov 2019)
MicroProfile 3.2
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.3
Fault�Tolerance 2.0
JWT�Propagation 1.1
Health 2.1
Metrics 2.2
Open Tracing 1.3
Open API 1.1
= Updated
= No change from last release (MicroProfile 3.1)
= New
Rest Client 1.3
JSON-B 1.0
Standalone
Context Propagation 1.0
Reactive Streams Operators 1.0
Outside umbrella
Reactive Messaging 1.0
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 3.3 (Feb 2020)
MicroProfile 3.3
JAX-RS 2.1
JSON-P 1.1
CDI 2.0
Config 1.4
Fault�Tolerance 2.1
JWT�Propagation 1.1
Health 2.2
Metrics 2.3
Open Tracing 1.3
Open API 1.1
= Updated
= No change from last release (MicroProfile 3.2)
= New
Rest Client 1.4
JSON-B 1.0
Standalone
Context Propagation 1.0
Reactive Streams Operators 1.0
Outside umbrella
Reactive Messaging 1.0
GraphQL 1.0
@rafabene - http://bit.ly/slides-microprofile
MicroProfile 4.0 Released!
Released December 23rd, 2020. Offered in the release:
Eclipse MicroProfile 4.0 (Dec 2020)
MicroProfile 4.0
Jakarta�JAX-RS 2.1
Jakarta�JSON-P 1.1
Jakarta�CDI 2.0
Config 2.0
Fault�Tolerance 3.0
JWT�Authentication 1.2
Health 3.0
Metrics 3.0
Open Tracing 2.0
Open API 2.0
= Updated
= No change from last release (MicroProfile 3.3)
= New
Rest Client 2.0
Jakarta�JSON-B 1.0
Standalone
Context Propagation 1.0
Reactive Streams Operators 1.0
Outside umbrella
Reactive Messaging 1.0
GraphQL 1.0
@rafabene - http://bit.ly/slides-microprofile
Eclipse MicroProfile 4.1 (Jul 2021)
MicroProfile 4.1
Jakarta�JAX-RS 2.1
Jakarta�JSON-P 1.1
Jakarta�CDI 2.0
Config 2.0
Fault�Tolerance 3.0
JWT�Authentication 1.2
Health 3.1
Metrics 3.0
Open Tracing 2.0
Open API 2.0
= Updated
= No change from last release (MicroProfile 4.0)
= New
Rest Client 2.0
Jakarta�JSON-B 1.0
Standalone
Context Propagation 1.0
Reactive Streams Operators 1.0
Outside umbrella
Reactive Messaging 1.0
GraphQL 1.0
@rafabene - http://bit.ly/slides-microprofile
MicroProfile 5.0 (Dec 7th 2021)
53
MicroProfile 5.0
Jakarta�JAX-RS 3.0
Jakarta�JSON-P 2.0
Jakarta�CDI 3.0
Config 3.0
Fault�Tolerance 4.0
JWT�Authentication 2.0
Health 4.0
Metrics 4.0
Open Tracing 3.0
Open API 3.0
= Updated
= No change from last release (MicroProfile 4.1)
= New
Rest Client 3.0
Jakarta�JSON-B 2.0
Standalone
Context Propagation 1.3
Reactive Streams Operators 2.0
Outside umbrella
Reactive Messaging 2.0
GraphQL 1.1
LRA 1.0
Jakarta�Annotations 2.0
@rafabene
@rafabene - http://bit.ly/slides-microprofile
Get Involved!
@rafabene - http://bit.ly/slides-microprofile
@RAFABENE
@rafabene - http://bit.ly/slides-microprofile