Emily Jiang gave a presentation on MicroProfile, a set of lightweight, open source APIs for Java microservices. She began with an overview of MicroProfile's history and community-driven development process. She then provided a deep dive on various MicroProfile specifications, including Config, REST Client, OpenAPI, JWT Auth, Fault Tolerance, Health, Metrics, Telemetry, and more. Finally, she discussed the future of MicroProfile, including upcoming versions that will adopt OpenTelemetry Metrics and make other updates.
10. 10
Use case: As a developer, I need to
create a microservice working in a
cloud.
11. Jakarta REST
B
@ApplicationPath("System")
public class SystemApplication extends
Application {}
@Path("properties")
public class PropertiesResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getProperties() {…}
}
12. 12
I need to configure my services in
my deployment environment
13. 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/
17. MicroProfile OpenAPI
A B
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/
18. 18
I need to protect my services to
prevent from unauthorized access
19. 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/
20. 20
I need to provide a good response
to my clients no matter what
happens.
21. 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/
22. 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
23. 23
I need to ensure they work in the
Cloud and observe them.
25. 25
I need my service to communicate
with Kubernetes so that requests
can be routed when my service is
ready.
26. 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/
27. MicroProfile Health 3.1
Startup Probe
Liveness Probe
Readiness Probe
mpHealth-3.1 feature Application 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. 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/
30. 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
31. 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, Netflix Atlas,
CloudWatch, Datadog, Dynatrace, Elastic, Ganglia, Graphite, Humio, Influx/Telegraf, JMX, KairosDB, New Relic, Prometheus, SignalFx,
Google Stackdriver, StatsD, and Wavefront.)
Micrometer and Prometheus meter registry included in
mpMetrics-5.0.
Provide other meter registries if you want to connect to a different
monitoring system.
32. 32
I need to identify the root cause if
something goes wrong.
33. 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/
34. MicroProfile Telemetry
34
• 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
35. 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
36. How MP Telemetry works
– https://openliberty.io/guides/microprofile-telemetry-jaeger.html
39. 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;
40. MicroProfile Health with Kubernetes
A B
readinessProbe:
httpGet:
path: /health/ready
port: 9080
initialDelaySeconds: 15
periodSeconds: 5
failureThreshold: 1
41. 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
46. 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
48. 48
How to do transactions in
microservices? SAGA pattern?
49. 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
50. 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 µS
Hotel
µS
Book Book
Flight
µS
Taxi µS
Hotel
µS
Confirm Confirm
Confirm
Start LRA
End LRA
Successful
Flight
µS
Book
Taxi µS
Hotel
µS
Book Book
Flight
µS
Book
Taxi µS
Hotel
µS
Book Book
Flight
µS
Taxi µS
Failed
Compensate
Compensate
Start LRA
End LRA
❌
Error
In the case of success, complete actions are invoked
51. 51
I need to frequently query/update
data. What should I do?
52. 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
60. MicroProfile in 2024
● MicroProfile 7.0 in 2Q 2024
○ Adopt OpenTelemetry Metrics in MicroProfile Telemetry 1.2/2.0
○ Move MicroProfile Metrics to be a standalone spec
○ Make Jakarta EE Core Profile dependency loosely coupled
○ Update other specifications accordingly
● New specifications
○ Evaluate a new specification: Converter
○ Evaluate a new specification: Serverless
60