Creating a cloud-native microservice - which programming model should I use? - EclipseCon

Page created by Kathy Obrien
 
CONTINUE READING
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
Creating a cloud-native microservice
      – which programming model should I use?

Emily Jiang, Java Champion

Senior Technical Staff Member, IBM
Liberty Microservice Architect, Advocate
Senior Lead for MicroProfile and CDI

@emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
@emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
MicroProfile

                                                           Specs, APIs, TCKs

                                                              No Reference
                                                                 Impls!

                                  Lightweight, Iterative
                                       Processes

               Community Driven

                                  @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
19.0.0.8

                               19.0.0.9
                                                                                MicroProfile 3.0 (Jun
                                                                                2019)
                                                                                     MicroProfile 2.2                             2021
  Jan                                                                                Health Check 2.0
                                              MicroProfile 1.4 (June                 Metrics 2.0
                                              2018)                                  Rest Client 1.3
                                                    MicroProfile 1.3                                  2020
                MicroProfile 1.3 (Dec 2017)         mpConfig-1.3
                      MicroProfile 1.2              mpFaultTolerance-1.1                                                            MicroProfile 3.1 (Oct
                      mpConfig-1.2                  mpJwt-1.1
                      mpMetrics-1.1                                                                                                 2019)
                                                    mpOpenTracing-1.1
                      mpOpenApi-1.0                                                                                                      MicroProfile 3.0
                                                    mpRestClient-1.1
                      mpOpenTracing-1.0                                  2019                                                            Health Check 2.1
                      mpRestClient-1.0                                                                                                   Metrics 2.1
                                                                                                             MicroProfile 2.2 (Feb 2019)
MicroProfile 1.1 (August                                                                                           MicroProfile 2.1
                                           2018                                     MicroProfile 2.1 (Oct 2018)    Fault Tolerance 2.0
2017)
      microProfile-1.0                                                                     MicroProfile 2.0        OpenAPI 1.1
      mpConfig-1.0                                                                         mpOpenTracing-1.2       OpenTracing 1.3
                                                                                                                   Rest Client 1.2
                                                                           MicroProfile 2.0.1 (July
                                              MicroProfile 1.2 (Sept 2017) 2018)
            2017                                    microProfile-1.1             MicroProfile 1.4
                                                    mpConfig-1.1                 jaxrs-2.1 // Java EE 8
            MicroProfile 1.0 (Fall 2016)            mpFaultTolerance-1.0         cdi-2.0    // Java EE 8
                  jaxrs-2.0                         mpHealth-1.0                 jsonp-1.1  // Java EE 8
                  cdi-1.2                                                        jsonb-1.0 // Java EE 8
                                                    mpMetrics-1.0
                  jsonp-1.0
                                                    mpJwt-1.0

                                                              @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
Latest release

                                                                             MicroProfile
                                                                                 3.1
            Open          Open API      Rest Client
                                                        Config 1.3
         Tracing 1.3        1.1            1.3

            Fault                          JWT           Health
          Tolerance      Metrics 2.0    Propagation     Check 2.0
                                                                                 9 Platform
             2.0                            1.1                                  Releases!

           CDI 2.0       JAX-RS 2.1     JSON-P 1.1    JSON-B 1.0

                     MicroProfile 3.0
                                                                                         20+
                     Standalone releases                                             Component
                                                                                      Releases!
                                            Reactive
                           Context                                Reactive
                                            Streams
                         Propagation                             Messaging
                                            Operators

                                                            @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
MicroProfile Implementations

✓ Open specifications
✓ Wide vendor support
✓ REST services
✓ OpenAPI support
✓ Security
✓ Fault Tolerance
✓ Configuration
✓ Metrics
✓ Health
✓ Open Tracing

                                                 https://wiki.eclipse.org/MicroProfile/Implementation

                                             @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
Spring                      MicroProfile
Getting started
Starter                     https://start.spring.io/    https://start.microprofile.io/
REST
REST Service                Spring MVC                  JAX-RS

Dependency Injection        Spring IoC & DI             CDI

API Documentation           Spring REST Docs            MP Open API

REST Client                 Spring MVC                  MP REST Client

JSON Binding/Processing
                            Feign
                            Bring Your Own Llibrary     JSON-B
                                                                                         Capabilities
                            Jackson, JSON-B             JSON-P
Reactive

Reactive                    Spring Reactor              MicroProfile Reactive Streams
                                                        Operator, RxJava
                            Use Kafka APIs to connect   MicroProfile Reactive
                            with Kafka                  Messaging
Handling 100s of Services
Configuration               Spring Boot Config          MP Config
                            Spring Cloud Config
Fault Tolerance             Netflix Hystrix             MP Fault Tolerance
Security                    Spring Security             EE Security
                            Spring Cloud Security       MP JWT Propagation
Operation Focus
Health Checks               Spring Boot Actuator        MP Health Check
Metrics                     Spring Boot Actuator        MP Metrics
Distributed Tracing         Spring Cloud Sleuth         MP@emilyfhjiang
                                                          Open Tracing
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
Getting started

https://start.microprofile.io
                                                https://start.spring.io/

                                @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
There’s a good chance you’ll use REST APIs

                   @emilyfhjiang
Creating a cloud-native microservice - which programming model should I use? - EclipseCon
REST

                       B

       @emilyfhjiang
REST Service

               Spring                   MicroProfile

                        @emilyfhjiang
Dependency Injection

                                       B

                       @emilyfhjiang
Dependency Injection

                                                      B

          Spring
                                       MicroProfile

                       @emilyfhjiang
Document API

        A        B

               @emilyfhjiang
Document APIs in Spring
1. Define the dependencies                              3. Define all necessary test classes

2. Define your Rest service

4. Use alwaysDo(), responseFileds(), requestPayload(), links(), fieldWithPath(), requestParameters(), pathParameters() to document

                              © 2018 IBM Corporation

                                                          @emilyfhjiang
MicroProfile OpenAPI
                                                                        http://localhost:9080/openapi

                                                              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:
                           http://localhost:9080/openapi/ui           summary: List inventory contents.
                                                                     description: Returns the currently stored host:properties pairs
                                                              in the inventory.
                                                                     operationId: listContents
                                                                     responses:

A                  B                                                    200:
                                                                        description: host:properties pairs stored in the inventory.
                                                                        content:
                                                                           application/json:
                                                                              schema:
                                                                                 $ref: '#/components/schemas/InventoryList’
                                                              ….

                                 @emilyfhjiang
Rest Clients

               A                   B

                   @emilyfhjiang
REST Clients

                                   Spring

                               MicroProfile

               @emilyfhjiang
JSON-B & JSON-P

           A                      B

                  @emilyfhjiang
JSON Binding/Processing

                                            Spring

                                          MicroProfile

                          @emilyfhjiang
JSON-B & JSON-P in MicroProfile

                      A                                                     B
public class InventoryList {

private List systems;

public InventoryList(List systems) {       ...
         this.systems = systems;
                                                       @GET
      }
                                                       @Produces(MediaType.APPLICATION_JSON)
                                                       public InventoryList listContents() {
public List getSystems() {
                                                       return manager.list();
        return systems;
                                                       }
      }

public int getTotal() {
        return systems.size();
      }
}

                                                   @emilyfhjiang
Reactive
          Spring

Use Spring Reactor
Directly use Kafka APIs or Spring boot
annotations to interact with Kafka
streams

          MicroProfile

MicroProfile Reactive Stream Operators
to work with Reactive Streams
Can also use RxJava
MicroProfile Reactive Messaging

                                         @emilyfhjiang
Handling 100s of Services

                @emilyfhjiang
Configuration

                A                   B

                    @emilyfhjiang
Configuration
Spring                           MicroProfile

                 @emilyfhjiang
Fault Tolerance

                  A                   B

                      @emilyfhjiang
Fault Tolerance

              Spring                   MicroProfile

                       @emilyfhjiang
Secure Microservices

                       A                   B

                           @emilyfhjiang
Security: Consuming Json Web Tokens

                                                       Spring

                                                      MicroProfile

                                      @emilyfhjiang
Handling 100s of collaborating services
  requires a strong operations focus

                  @emilyfhjiang
Health
         Spring                   MicroProfile

                  @emilyfhjiang
Metrics

                          Spring

                            MicroProfile

          @emilyfhjiang
Distributed Tracing
               Spring Cloud Sleuth
                                                                                                   Spring
               If the Spring cloud sleuth is configured on the class path, the trace information
               will get generated automatically.

               MP OpenTracing
               Configuring this features allows us to generate traces for the application
                                                                                                    MicroProfile
               Custom Trace Implementation

                                                      @emilyfhjiang
Demo
       https://start.microprofile.io

                          @emilyfhjiang
Takeaway

ØDevelopers should be free to choose what                 ØSpring is popular
 they prefer                                              ØMicroProfile and Jakarta EE are evolving
ØEnterprise should provide developers with                 rapidly (and gaining momentum) as
 platforms that enable innovation and                      community-driven and standards-based
 flexibility and are enterprise and production             efforts for developing microservices and
 ready                                                     cloud-native applications in enterprise Java
ØLiberty supports both MicroProfile/EE and                ØBoth Spring and MicroProfile provide
 Spring                                                    facilities for developers to build next-
                                                           generation applications for cloud
 Ø Fast, small, reliable runtime
                                                           Ø Share similarities
 Ø Optimized for containers and cloud                      Ø There are differences too (and sometimes,
 Ø True liberty for microservice developers                  significant)
   and administrators                                     ØLightweight runtimes for Java/Jakarta EE are
                                                           readily available nowadays

                                              @emilyfhjiang
Spring Impl                   MicroProfile Impl
API     Open Source                   Open Source
s
        Driven by Pivotal             Driven by Community

        Spring way of things          Open standards
                                      Behaviors in accordance
                                      specifications
Line    More code                     Less code
s of
Cod
e       Do what you want/need with    Customize server configuration
        code (and configuration)
Libr    Find, mix and match what you Runtime provides what is needed
arie
s/De    like                         per specifications
pen     Manage your own dependencies
den
cies
App     Fat JARs                      Thin WAR
licat
ion
Pac
kagi
ng
                                     @emilyfhjiang
References

             ●   https://www.ibm.com/blogs/bluemix/2018/09/migrate-java-microservices-from-spring-to-
                 microprofile-p1/

             ●   https://www.eclipse.org/community/eclipse_newsletter/2019/september/microprofile.php

             ●   https://microprofile.io
                  ○ https://projects.eclipse.org/projects/technology.microprofile
                  ○ https://microprofile.io/projects/
                  ○ https://wiki.eclipse.org/MicroProfile/Implementation

             ●   https://openliberty.io
                  ○ https://openliberty.io/guides/
                  ○ https://openliberty.io/downloads/
                  ○ https://github.com/OpenLiberty/open-liberty

                                                         @emilyfhjiang
Thank You!

         @emilyfhjiang
You can also read