1 of 57

1

Microprofile

Specs from 1.0 to 5.0

rbenevides@microsoft.com

Link

2 of 57

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

3 of 57

What is Eclipse Microprofile?

  • Eclipse MicroProfile is an open-source community specification for Enterprise Java microservices
  • A community of individuals, organizations, and vendors collaborating within an open source (Eclipse) project to bring microservices to the Enterprise Java community

4 of 57

Community - individuals, organizations, vendors

5 of 57

Current MicroProfile Implementations

5

6 of 57

MicroProfile 1.0 (Sep, 2016)

MicroProfile 1.0

JAX-RS 2.0

JSON-P 1.0

CDI 1.2

7 of 57

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

8 of 57

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

9 of 57

Configuration

By default there are 3 default config sources:

  • System.getProperties() (ordinal=400)
  • System.getenv() (ordinal=300)
  • all META-INF/microprofile-config.properties files. (default ordinal=100)

@Inject

@ConfigProperty(name = "preference.api.url",

defaultValue = "http://localhost:8180/")

private String preferenceURL;

10 of 57

Configuration

CDI

CDI

11 of 57

11

Configuration

getPropertyNames()

getConfigSources()

getValue(...)

@rafabene

12 of 57

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

13 of 57

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

14 of 57

Health Check 1.0 - Goals

  • MUST be compatibility with well known cloud platforms (i.e. http://kubernetes.io/docs/user-guide/liveness/)
  • MUST be appropriate for machine-to-machine communication
  • SHOULD give enough information for a human administrator

15 of 57

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();

}

}

}

16 of 57

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();

}

}

}

17 of 57

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

18 of 57

Metrics 1.0 - Goals

  • Alternative to JMX but for a polyglot environment
  • Standard
    • API path,
    • data types involved,
    • always available metrics
    • return codes used

19 of 57

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

20 of 57

Metrics 1.0 - Goals

General

  • UsedHeapMemory
  • CommittedHeapMemory
  • MaxHeapMemory
  • GCCount & GCTime
  • JVM Uptime

Thread

  • ThreadCount
  • DaemonThreadCount
  • PeakThreadCount
  • ActiveThreads
  • PoolSize

ClassLoading

  • LoadedClassCount
  • TotalLoadedClassLoaded
  • UnloadedClassCount

Operating System

  • AvailableProcessors
  • SystemLoadAverage
  • ProcessCpuLoad

21 of 57

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)

22 of 57

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

23 of 57

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

24 of 57

Fault Tolerance 1.0

@Timeout

  • Define a duration for timeout

@Retry

  • Define a criteria on when to retry

@Fallback

  • Provide an alternative solution for a failed execution

@Bulkhead

  • Isolate failures in part of the system while the rest of the system can still function

@CircuitBreaker

  • Offer a way of fail fast by automatically failing execution to prevent the system overloading and indefinite wait or timeout by the clients

25 of 57

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();

}

26 of 57

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

27 of 57

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:

28 of 57

What is JWT?

29 of 57

JWT Usage

JAX-RS & OpenAPI

30 of 57

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

31 of 57

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.

32 of 57

OpenAPI 1.0

33 of 57

SECTION

OpenAPI

@rafabene

Open API

33

34 of 57

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.

35 of 57

  • A type-safe approach to invoke RESTful services over HTTP�
  • More natural coding style�
  • Handles HTTP connectivity and serialization

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 );

36 of 57

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.

37 of 57

37

Open tracing

38 of 57

39 of 57

Open Tracing - Jaeger

40 of 57

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

41 of 57

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

42 of 57

Eclipse MicroProfile 2.0 - Goals

  • Alignment of Java EE related APIs to Java EE 8 release:

  • Updated CDI, JSON-P, JAX-RS, and added JSON-B

43 of 57

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

44 of 57

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

45 of 57

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

46 of 57

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

47 of 57

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

- Project page

- Spec PDF doc

- Spec HTML doc

- Technology Compatibility Kit (TCK)

Check it out and send us your feedback!

- Project page

- Spec PDF doc

- Spec HTML doc

- Technology Compatibility Kit (TCK)

- Project page

- Spec PDF doc

- Spec HTML doc

- Technology Compatibility Kit (TCK)

48 of 57

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

49 of 57

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

50 of 57

MicroProfile 4.0 Released!

Released December 23rd, 2020. Offered in the release:

  • First release under the MicroProfile Working Group and MicroProfile Specification Process�
  • Updated to Jakarta CDI, JSON-P, JSON-B, and JAX-RS (that align with Jakarta EE 8, javax.* namespace)�
  • A richer feature set for all specifications, like
    • Configuration profiles (dev, test, prod)
    • JWT 1.2 - Tokens in cookies

51 of 57

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

52 of 57

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

53 of 57

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

54 of 57

@rafabene

  • Generate MicroProfile projects�
  • Visual Studio Code plugin�
  • Command line tooling

55 of 57

56 of 57

Get Involved!

57 of 57

@RAFABENE