MicroProfile - Towards a Microservices Standard for Java

Cd94eaef7b2860c41cb0612720137e2b?s=47 Reza Rahman
December 07, 2018

MicroProfile - Towards a Microservices Standard for Java

MicroProfile is an open-source specification that brings a number of microservices features to Java EE. It was born out of the need to accelerate Java EE innovation and serves as an incubator to eventual standardization via Jakarta EE. MicroProfile features include Open Tracing, Open API, dynamic configuration, fault tolerance, a type-safe REST client, metrics, health checks and JWT propagation. MicroProfile is supported by major industry players like IBM, Red Hat, Oracle, Microsoft, Payara and Tomitribe.

This session is a fast paced look at the current state of MicroProfile. This includes motivation, history, latest changes, road map and a code example driven tour of features.

Cd94eaef7b2860c41cb0612720137e2b?s=128

Reza Rahman

December 07, 2018
Tweet

Transcript

  1. MicroProfile Towards a Microservices Standard for Java Reza Rahman

  2. Agenda • Introductions • Past, Present and Future • Feature

    Tour • Summary
  3. Introductions

  4. What is MicroProfile? • MicroProfile is an open-source specification that

    brings a number of microservices features to Java EE • Born out of the need to accelerate Java EE innovation and serves as an incubator • MicroProfile features may be eventually included in Jakarta EE proper
  5. MicroProfile JAX-RS JSON-P CDI Dynamic Configuration Fault Tolerance JWT Propagation

    Health Check Metrics Open Tracing Open API Type-Safe REST Client JSON-B
  6. Community

  7. Implementations

  8. Past, Present and Future

  9. MicroProfile 1.0 (September 2016) MicroProfile 1.0 JAX-RS 2.0 JSON-P 1.0

    CDI 1.2
  10. MicroProfile 1.1 (August 2017) MicroProfile 1.1 JAX-RS 2.0 JSON-P 1.0

    CDI 1.2 Config 1.0 = No change from last release = New
  11. MicroProfile 1.2 (September 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
  12. MicroProfile 1.3 (January 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
  13. MicroProfile 1.4 (June 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
  14. MicroProfile 2.0 (June 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 = New Rest Client 1.1 JSON-B 1.0
  15. MicroProfile 2.1 (October 2018) 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 = Updated = No change from last release = New Rest Client 1.1 JSON-B 1.0
  16. MicroProfile 2.2 (February 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 = New Rest Client 1.2 JSON-B 1.0
  17. Open Tracing 1.3 • Instrument MicroProfile Rest Client 1.2 •

    Clarify http-path when path contains regular expressions • Clarified default skip pattern value • Added HTTP method to http-path operation name
  18. Open API 1.1 • Addition of the JAX-RS 2.1 PATCH

    method • Automatically hide MicroProfile Rest Client interfaces • Builder methods now have default implementations • @Content now supports a singular example field • @Extension now has a parseValue field for complex values
  19. Rest Client 1.2 • Generate headers en masse, including propagation

    of headers from inbound JAX-RS requests • New @ClientHeaderParam API for defining HTTP headers without modifying the client interface method signature • New connectTimeout and readTimeout methods on RestClientBuilder - and corresponding MicroProfile Configuration properties • New removeContext method for AsyncInvocationInterceptor interface
  20. Fault Tolerance 2.0 • Adopting CDI 2/Java EE 8 •

    Support for CompletionStage return type when annotated with @Asynchronous • Specify invocation sequence of MicroProfile Fault Tolerance annotations when used together
  21. Other Changes • Reactive Streams Operators 1.0 released standalone •

    GraphQL sandbox approved • Health Check 2.0 planning to release stand-alone • Metrics 2.0 planning to release stand-alone • MicroProfile Starter (beta) available!
  22. MicroProfile 3.0 (June 2019) MicroProfile 3.0 = Updated = No

    change from last release = New 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 Rest Client 1.2 JSON-B 1.0 Outside Concurrency 1.0 LRA 1.0 Reactive Streams Operators 1.1 Umbrella GraphQL 1.0
  23. Topics Under Discussion • Long Running Actions • Reactive Messaging

    • GraphQL • Concurrency • Reactive Relational Database Access • Event Data • Service Meshes
  24. Feature Tour

  25. Open API • Generates Open API (Swagger) documents from JAX-RS

    endpoints • Basically WSDL for REST • Enabled by default in all MicroProfile applications
  26. Open API Example @GET @Operation(description="Get all current memberships") @APIResponses({ @APIResponse(responseCode="200",

    description="Successful, returning memberships"), ... }) public List<Membership> getAllMemberships() {
  27. Open Tracing • Tracing the flow of a request in

    a distributed environment has always been challenging • Open Tracing provides a standard for instrumenting microservices for distributed tracing ◦ Jaeger, Zipkin • Enterprise Java binding to the Open Tracing specification
  28. Open Tracing Example @GET @Path("{id}") @Traced(operationName="GetMembershipById", value=true) public Membership getMembership(

    @NotNull @PathParam(value="id") int id) {
  29. JWT Propagation • REST 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 • Basically what OAuth2, OpenID Connect (OIDC) and JSON Web Tokens (JWT) do • Think of it as SAML for REST • Enterprise Java binding for the JWT specification
  30. JWT Propagation Example @GET @RolesAllowed({"admin"}) public List<Membership> getAllMemberships() {

  31. Configuration • Java EE mostly focuses on static configuration •

    Applications may need to be configured based on a running environment • It should be possible to modify configuration values from outside an application so that the application itself does not need to be repackaged • Property files, system properties, environment variables • Influenced by DeltaSpike Config and Apache Tamaya
  32. Configuration Example @Inject @ConfigProperty(name="host.name", defaultValue="localhost") private String hostname;

  33. Rest Client • JAX-RS provides a powerful client API, but

    it can be hard to use and not really type safe • Several JAX-RS implementations support ability to take an interface definition (typically for a JAX-RS endpoint) and create a JAX-RS client from it (JBoss RESTEasy, Apache CXF) • Basically similar to JAX-WS/SOAP clients • MicroProfile standardizes this capability 33
  34. Rest Client Example String apiUrl = "http://localhost:9080/movieReviewService"; MovieReviewService reviewService =

    RestClientBuilder.newBuilder() .baseUrl(apiUrl) .build(MovieReviewService.class); Review review = new Review(3 /*stars*/, "Good Movie."); reviewService.submitReview(movie, review);
  35. Health Check • Health checks probe state of a computing

    node from another machine (such as the Kubernetes service controller) • Primary target cloud environments where automated processes maintain the state of computing nodes
  36. Health Check Example @Health @ApplicationScoped public class CheckDiskSpace implements HealthCheck

    { ... public HealthCheckResponse call() { ... } }
  37. Metrics • Monitoring key to distributed systems ◦ Human and

    automated • Metrics adds well-known monitoring endpoints and values for each process ◦ Required base metrics ◦ Application metrics ◦ Vendor-specific metrics • Primary target cloud environments with distributed metrics registries/consoles ◦ Prometheus/Kubernetes
  38. Metrics Example @GET @Timed(name="get_all_memberships_time", absolute=true, unit=MetricUnits.MICROSECONDS) public List<Membership> getAllMemberships() {

    ... @POST @Counted(name="memberships_created", absolute=true, monotonic=true) public Membership createMembership( ... Membership membership){
  39. Fault Tolerance • 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 • Influenced by Hystrix/Failsafe
  40. Fault Tolerance Example @GET @Path("{id}") @CircuitBreaker(failOn=RuntimeException.class, requestVolumeThreshold=1, failureRatio=1, delay=10, delayUnit=ChronoUnit.SECONDS)

    @Timeout(value=3, unit=ChronoUnit.SECONDS) @Bulkhead(2) public Membership getMembership( @NotNull @PathParam(value = "id") int id) {
  41. Summary • MicroProfile fills an important gap with Java EE

    and microservices • May eventually be merged with Jakarta EE • Vibrant community, fast pace of innovation • Time to get involved is now!
  42. Resources • http://microprofile.io • https://start.microprofile.io • https://projects.eclipse.org/projects/technology.microprofile • https://wiki.eclipse.org/MicroProfile •

    https://groups.google.com/forum/#!forum/microprofile
  43. None