Master a Cloud Native Standard - MicroProfile.pdf

EmilyJiang23 31 views 43 slides May 19, 2024
Slide 1
Slide 1 of 63
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63

About This Presentation

This deck covers the latest MicroProfile technologies including the standard alone MicroProfile specifications.


Slide Content

Emily Jiang, Java Champion
IBM, STSM, Cloud Native Architect and Advocate
16th May 2024
Master a Cloud Native
Application Standard:
MicroProfile

Agenda
01
02
03
2
MicroProfile Background
MicroProfile Deep Dive
MicroProfile Future

Community
Driven
Lightweight,
Iterative Processes
Specs, APIs, TCKs

Implementations
WebSphere
Liberty

Working Group members

MicroProfile 1.0
(Fall 2016)
MicroProfile 1.1
(Aug. 2017)
MicroProfile 1.2
(Sept 2017)
2017
2018
MicroProfile 1.3
(Dec 2017)
MicroProfile 1.4
(June 2018)2019
MicroProfile 2.0.1
(July 2018)
MicroProfile 2.1
(Oct 2018)
MicroProfile 2.2
(Feb 2019)MicroProfile 3.0
(June 2019)
MicroProfile 3.2
(Nov 2019)
2020
MicroProfile 3.3
(Feb 2020)
MicroProfile 4.0
(Oct. 2020)
MicroProfile 4.1
(July. 2021)
MicroProfile 5.0
(Dec. 2021)
Config 3.0
Metrics 4.0
Fault Tolerance 4.0
Health 4.0
Rest Client 3.0
OpenAPI 3.0
OpenTracing 3.0
JWT Auth 2.0
Jakarta CDI 3.0 //Jakarta EE 9.1
Jakarta RESTful Web Services //Jakarta EE 9.1
Jakarta JSON-P //Jakarta EE 9.1
Jakarta JSON-B 2.0 //Jakarta EE 9.1
Jakarta Annotations 2.0 //Jakarta EE 9.1
2022
2021
MicroProfile 6.0
(Dec. 2022)
Config 3.0
Metrics 5.0
Fault Tolerance 4.0
Health 4.0
Rest Client 3.0
OpenAPI 3.1
Telemetry 1.0
JWT Auth 2.1
Jakarta EE 10 Core Profile
MicroProfile 6.1
(Oct. 2023)
Config 3.1
Metrics 5.1
Fault Tolerance 4.0
Health 4.0
Rest Client 3.0
OpenAPI 3.1
Telemetry 1.1
JWT Auth 2.1
Jakarta EE 10 Core
Profile
2023
2024
MicroProfile 7.0
(2024)
Config 3.1
Fault Tolerance 4.1
Health 4.0
Rest Client 4.0
OpenAPI 4.0
Telemetry 2.0
JWT Auth 2.1

MicroProfile
HealthMetrics
Fault
ToleranceOpen APIConfig
Telemetry
JWT
Rest Client
GraphQL
Reactive
Streams
Operators
Reactive
Messaging
Context
Propagation
Platform Release
Standalone Release
Jakarta EE
Core Profile
LRA
Open Tracing

MicroProfile 6.1 in Oct. 2023
Health 4.0Metrics 5.1
Fault
Tolerance 4.0Open API 3.1Config 3.1
Telemetry 1.1
JWT 2.1
Rest Client
3.0
Jakarta EE 10
Core Profile
Updated specsUnchanged specsJakarta EE 10 Core Profile specs
Core
Integrate
Observe

MicroProfile 7.0 in 2024
Health 4.0
Fault
Tolerance 4.1Open API 4.0Config 3.1
Telemetry 2.0
JWT 2.1
Rest Client
4.0
Jakarta EE 10
Core Profile
Updated specsUnchanged specsJakarta EE 10 Core Profile specs
Core
Integrate
Observe
–The release date is subject to change.

Agenda
01
02
03
10IBM TechXchange / © 2023 IBM Corporation
MicroProfile background
MicroProfile Deep Dive
MicroProfile future

11
Use case: As a developer, I need
to create a microservice working
in a cloud.

Jakarta REST
B
@ApplicationPath("System")
public class SystemApplication extends
Application {}
@Path("properties")
public class PropertiesResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getProperties() {…}
}

13
I need to configure my services in
my deployment environment

A
MicroProfile Config
B
@Inject
@ConfigProperty(name = "inMaintenance")
private Provider<Boolean> inMaintenance;
config_ordinal=100
inMaintenance=false
{
"config_ordinal":150,
"inMaintenance":true
}
https://github.com/eclipse/microprofile-config/

15
I want to call other microservices

MicroProfile REST Client
BA
@Inject
@RestClient
private SystemClient defaultRestClient;
@Dependent
@RegisterRestClient
@RegisterProvider(UnknownUrlExceptionMapper.class)
@Path("/properties")
public interface SystemClient {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Properties getProperties() throws
UnknownUrlException, ProcessingException;
}
io.openliberty.guides.inventory.client.SystemClient/mp-rest/url=http://localhost:9080/system
https://github.com/eclipse/microprofile-rest-client

17
What does the service do?

MicroProfile OpenAPI
AB
openapi: 3.0.0
info:
title: Inventory App
description: App for storing JVM system properties of various
hosts.
license:
name: Eclipse Public License - v 1.0
url: https://www.eclipse.org/legal/epl-v10.html
version: "1.0"
servers: - url: http://localhost:{port} description: Simple Open
Liberty.
variables:
port:
description: Server HTTP port.
default: "9080"
paths:
/inventory/systems:
get:
summary: List inventory contents.
description: Returns the currently stored host:properties
pairs in the inventory.
operationId: listContents
responses:
200:
description: host:properties pairs stored in the inventory.
content:
application/json:
schema:
$ref: '#/components/schemas/InventoryList’
….
http://localhost:9080/openapi/ui
https://github.com/eclipse/microprofile-open-api/

19
I need to protect my services to
prevent from unauthorized
access

MicroProfile JWT
A B
@GET
@RolesAllowed({ "admin", "user" })
@Path("{hostname}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPropertiesForHost(@PathParam("hostname") String hostname,
@Context HttpHeaders httpHeaders) {…}
https://github.com/eclipse/microprofile-jwt-auth/

21
I need to provide a good
response to my clients no matter
what happens.

MicroProfile Fault Tolerance
A B
@Fallback(fallbackMethod = "fallbackForGet")
public Properties get(String hostname) throws IOException
{
return invUtils.getProperties(hostname);
}
https://github.com/eclipse/microprofile-fault-tolerance/

MicroProfile Fault Tolerance
–The annotations can be used together.
–When MicroProfile Metrics is enabled, their usages are monitored.
–The values can be configured via MicroProfile Config.
@Retry@Timeout@CircuitBreaker
@Bulkhead@Asynchronous@Fallback

24
I need to ensure they work in the
Cloud and observe them.

MicroProfile
HealthMetrics
Fault
ToleranceOpen APIConfig
Telemetry
JWT
Rest ClientJakarta EE
Core Profile

26
I need my service to
communicate with Kubernetes
so that requests can be routed
when my service is ready.

MicroProfile Health
A B
@Readiness
@ApplicationScoped
public class InventoryResource implements HealthCheck {
...
public boolean isHealthy() {...}
@Override
public HealthCheckResponse call() {
if (!isHealthy()) {
return
HealthCheckResponse.named(“ServiceHealthCheck”).withData(…).down().build();
}
return
HealthCheckResponse.named(“ServiceHealthCheck”).withData(…).up().build();
}
} https://github.com/eclipse/microprofile-health/

MicroProfile Health 3.1
Startup Probe
Liveness Probe
Readiness Probe
mpHealth-3.1 featureApplication provided health
checks
/health
/health/ready
/health/live
Health Check D
@Readiness
Health Check E
@Readiness
Health Check C
@Liveness
/health/started
Health Check A
@Startup
Health Check B
@Startup
Application 1
HTTP GET
In Kubernetes, when the startup probe is
configured, the liveness and readiness checks
are disabled, until it succeeds.
Kubernetes

29
I need to know how my service is
performing.

MicroProfile Metrics
A B
@Timed(name = "inventoryPropertiesRequestTime”,
description = "Time needed to get the properties of" +
"a system from the given hostname")
public Properties get(String hostname) {
return invUtils.getProperties(hostname);
}
https://github.com/eclipse/microprofile-metrics/

MicroProfile Metrics 5.1
Influenced by Micrometer
All metrics are under /metrics endpoint.
Data is returned from /metrics calls in the Prometheus 0.0.4 exposition format.
Implementation can use Micrometer or OpenTelemetry Metrics

MicroProfile Metrics 5.1
Liberty mpMetrics-5.1
•Tracks metrics from Liberty components and the JVM to help you understand how your servers are performing.
•Provides the MicroProfile Metrics API, which you can use to add metrics to your applications.
•Provides the ability to group application metrics into custom scopes and allows querying of metrics by those scopes.
•Is based on Micrometer - can ship metrics to your choice of monitoring systems (currently including AppOptics,Azure Monitor, NetflixAtlas,
CloudWatch, Datadog, Dynatrace, Elastic,Ganglia,Graphite,Humio,Influx/Telegraf,JMX,KairosDB,New Relic, Prometheus, SignalFx,
GoogleStackdriver,StatsD, andWavefront.)
Micrometer and Prometheus meter registry included in
mpMetrics-5.0.
Provide other meter registries if you want to connect to a different
monitoring system.

33
I need to identify the root cause
if something goes wrong.

MicroProfile Telemetry
A B
@WithSpan(name=“list”)
public InventoryList list() {
return new InventoryList(systems);
}
Jakarta REST methods are
automatically traced by default
https://github.com/eclipse/microprofile-telemetry/

MicroProfile Telemetry
35
•Adopts OpenTelemetry Tracing
•Set of APIs, SDKs, tooling and integrations
•Designed for the creation and management of
telemetry data (traces, metrics, and logs)
•Supports 3 instrumentations:
•Manual
•Automatic
•Java Agent

MicroProfile Telemetry
•Support Java agent instrumentation
-javaagent:opentelemetry-javaagent.jar
-Dotel.service.name=<name>
-Dotel.traces.exporter=jaeger
-Dotel.instrumentation.opentelemetry-api.enabled=false
•Automatically tracing of REST (server and client) calls, and MicroProfile REST Client calls
without code modification.
•Manual instrumentation using OpenTelemetry API
–@WithSpan
–@SpanAttribute
–@Inject io.opentelemetry.api.OpenTelemetry
–@Inject io.opentelemetry.api.trace.Tracer
–@Inject io.opentelemetry.api.trace.Span
–@Inject io.opentelemetry.api.baggage.Baggage
java -javaagent:path/to/opentelemetry-javaagent.jar \
-Dotel.service.name=your-service-name \
-Dotel.traces.exporter=zipkin \
-jar myapp.jar

How MP Telemetry works
–https://openliberty.io/guides/microprofile-telemetry-jaeger.html

38
Done the development. Time to
deploy to my chosen Cloud. How
to do it?

Cloud-Native Application Deployment
KubernetesIstio
Docker
or
Podman
HealthMetrics
Fault
ToleranceOpen APIConfig
Open Tracing
JWT
Rest ClientJakarta EE
Core Profile

MicroProfile Config with Kubernetes
A B
env:
- name: GREETING
valueFrom:
configMapKeyRef:
name: greeting-config
key: message
kubectl create configmap greeting-config --from-literal message=Hello...
@Inject
@ConfigProperty(name = "GREETING")
private String greeting;

MicroProfile Health with Kubernetes
A B
readinessProbe:
httpGet:
path: /health/ready
port: 9080
initialDelaySeconds: 15
periodSeconds: 5
failureThreshold: 1

MicroProfile Metrics with Kubernetes
A B
@POST
@Counted(name="order", displayName="Order count",
description="Number of times orders requested.")
public Response orderCoffee(@Valid @NotNull CoffeeOrder order) {
...
}
Data in OpenMetrics
format
Collect and store data
with Prometheus
Visualize data with
Grafana

MicroProfile Telemetry
7 HTTP headers required by Istio propagated
All Jakarta REST
requests traced

Istio & MicroProfile - Putting it all together

45
I need to create a reactive
microservice.

MicroProfile Reactive Messaging
Reactive Messaging is based on Reactive Streams Operators

MicroProfile Reactive Messaging
The MicroProfile Reactive Messaging API provides a simple way to configure the streams and event queues
using annotations
–https://openliberty.io/guides/microprofile-reactive-messaging.html

MicroProfile Reactive Messaging 3.0
Imperative code bridges with reactive code

49
How to do transactions in
microservices? SAGA pattern?

MicroProfile LRA
•Cloud Native Transaction model based on compensating Saga model
•Loosely coupled µServices with eventually consistent data
LRA Coordinator
µS AµS BµS C
•Orchestration via a Coordinator Service that Participant
µServices registers with
•Annotations for joining, completing and compensating
transactions

MicroProfile LRA
Need to maintain data consistency across multiple µservices where each has their own data.
The multiple operations form the atomic action which needs to be process together
In the case of failures compensation actions are invoked
Flight
µS
Book
Taxi µSHotel
µS
BookBook
Flight
µSTaxi µSHotel
µS
ConfirmConfirm
Confirm
Start LRA
End LRASuccessful
Flight
µS
Book
Taxi µSHotel
µS
BookBook
Flight
µS
Book
Taxi µSHotel
µS
BookBook
Flight
µSTaxi µS
FailedCompensate
Compensate
Start LRA
End LRA

Error
In the case of success, complete actions are invoked

52
I need to frequently
query/update data. What should
I do?

MicroProfile GraphQL
•Avoiding over-fetching or under-fetching
data.
•Enabling data models to evolve, schema
driven.
•Provide a "code-first" set of APIs that will
enable users to quickly develop portable
GraphQL-based applications in Java
–GraphQL Entities
Scalars, or simple type
Enumerable types (similar to Java Enum)
Complex objects : scalars and/or enums and/or other complex objects and/or collections of these.
–GraphQL Components
–@GraphQLApi : GraphQL endpoints must be annotated with the @GraphQLApi annotation.
–@Query: allows a user to ask for all or specific fields on an object or collection of objects.
–@Mutation: create new entities or update or delete existing entities.
–https://openliberty.io/guides/microprofile-graphql.html

54
I am convinced to use
MicroProfile. Where to start?

How to get started?
https://start.microprofile.io/

Open Liberty Starter
https://start.openliberty.io

57
Are there any learning
materials?

Learning materials
–https://openliberty.io/guides/?search=microprofile
–https://github.com/Emily-Jiang/jcon
–https://microprofile.io/

59
MicroProfile Book featured Open Liberty
https://ibm.biz/MicroProfileBook
Twitter/LinkedIn: @emilyfhjiang

Agenda
01
02
03
60IBM TechXchange / © 2023 IBM Corporation
MicroProfile background
MicroProfile Deep Dive
MicroProfile future

MicroProfile in 2024
●MicroProfile 7.0 in 3Q 2024
○Adopt OpenTelemetry Metrics in MicroProfile Telemetry 2.0
○Move MicroProfile Metrics to be a standalone spec
○Make Jakarta EE Core Profile dependency loosely coupled
○The updated specifications: Telemetry 2.0, Fault Tolerance 4.1, OpenAPI 4.0, Rest
Client 4.0
●New specifications
○Evaluate a new specification: AI with the focus on LLM
■If interested, join the weekly Monday AI group discussions
61

62
Q&A
Emily Jiang
IBM, Cloud Native Architect & Advocate
[email protected]
Twitter/LinkedIn: @emilyfhjiang