Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effective cloud-ready apps with MicroProfile

Effective cloud-ready apps with MicroProfile

Presented during Payara Japan Tour 2019 (https://blog.payara.fish/payara-on-tour-in-japan).

In this session, you'll learn how to develop applications that evolve according to your needs, can easily run in the cloud and integrate with common cloud technologies. We'll start with a simple application, focusing on business logic. MicroProfile framework, powered by a lightweight opensource Payara Micro runtime, will get us started quickly and allow gradual improvements later.

MicroProfile contains a lot of components that make developers productive. It allows separating business logic from common concerns like configuration, failure-recovery, REST service calls, context propagation across service calls and securing services. Adding all of these to existing code is easy. It's also easy to introduce new microservices as needed and adopt cloud technologies as your application grows. I'll show you how, in a step-by-step demo. And if time allows, I'll also show how to run and scale your application effectively with Kubernetes in the cloud.

(日本語訳) このセッションでは、皆様がニーズに合わせて発展するアプリケーションの開発手法を学び、アプリケーションをより簡単にクラウド上で実行して共通のクラウド技術と連携させることができるようにご案内します。私達はまずシンプルなアプリケーションからスタートして、徐々にビジネス・ロジックへとフォーカスしてゆきます。MicroProfileフレームワークを用いて、軽量なオープンソースのPayara Microランタイム上で素早く立ち上げ、後から徐々に進化させられる様子をご覧いただけます。

MicroProfileには開発者の生産性を高める多くのコンポーネントが含まれています。MicroProfileを用いると、構成、障害復旧、RESTサービス呼び出し、サービス呼び出し間のコンテキスト伝搬、サービスのセキュア化といった共通的関心事をビジネス・ロジックを共通的関心事から分離することができます。これらはすべて、簡単に既存のコードに加えることができます。また、必要に応じて新しいマイクロサービスを導入し、アプリケーションの成長に合わせてクラウド技術を採用するのも容易です。その具体的な方法について、ステップ・パイ・ステップのデモをご覧いただきたいと思います。また時間が許せば、Kubernatesを用いてアプリケーションをクラウド上で効果的に実行・スケールさせる方法についてもご説明したいと思います。

Ondro Mihályi

May 13, 2019
Tweet

More Decks by Ondro Mihályi

Other Decks in Technology

Transcript

  1. Effective cloud-ready apps
    with MicroProfile
    Ondro Mihályi, Payara, http://www.payara.fish
    @ONDROMIH

    View Slide

  2. @OMIHALYI
    What is cloud ready?

    Spring, Java EE / Jakarta EE,
    MicroProfile or Lagom

    AWS, Azure or Openshift

    SQL or NoSQL

    REST or EJB

    View Slide

  3. @OMIHALYI
    Is it really about technology?

    View Slide

  4. @OMIHALYI
    Even cool tech can be painful

    View Slide

  5. Cloud ready requirements

    Pluggable services

    Scalable according to
    the load

    Low coupling
    There are even more according to the 12 factor applications manifesto

    External configuration

    Failure recovery

    Security

    Monitoring

    View Slide

  6. @OMIHALYI
    Solution: agile evolution

    Simple API abstractions

    Flexible implementations

    Application logic first, against a solid platform

    Abstract the technology, prepare for refactoring

    Choose final technology later

    View Slide

  7. @OMIHALYI
    Cloud-ready architecture

    View Slide

  8. @OMIHALYI
    SCALABLE RUNTIME

    View Slide

  9. @OMIHALYI

    View Slide

  10. @OMIHALYI
    What is Payara Micro?

    Executable JAR (~70MB disk size, ~30 MB RAM)

    Runs WAR and EAR from command line
    – Also Uber JAR, embeddable, maven plugin

    Automatically forms elastic cluster

    Web Profile and most of Full Profile, MicroProfile

    Opensource, release each 3 months

    View Slide

  11. @OMIHALYI
    What is MicroProfile?

    Project at Eclipse Foundation

    Common API, multiple implementations

    Builds on Java EE standards

    Modern patterns:
    – Microservices, Reactive, …

    http://microprofile.io - open for everybody

    View Slide

  12. @OMIHALYI

    View Slide

  13. @OMIHALYI
    COMMUNICATION (REST)

    View Slide

  14. @OMIHALYI
    REST API

    View Slide

  15. @OMIHALYI
    REST services API (server)

    JAX-RS endpoint
    public User getUser(
    Integer id) {
    return userById(id);
    }

    View Slide

  16. @OMIHALYI
    REST services API (server)

    JAX-RS endpoint
    @GET
    @Path("{id}")
    @Produces(MediaType.APPLICATION_JSON)
    public User getUser(
    Integer id) {
    return userById(id);
    }
    @PathParam("id")

    View Slide

  17. @OMIHALYI
    REST services API (client)

    JAX-RS client
    User admin = client.target(url).path("admin")
    .request().get(User.class)

    MicroProfile client (plain Java interface - much better abstraction)
    User admin = userService.getUser("admin")

    View Slide

  18. @OMIHALYI
    JSON binding
    @JsonbNillable
    public class User implements Serializable {
    private String name;
    @JsonbTransient
    private String description;
    @JsonbProperty("userId")
    private long id;
    }
    - new in Java EE 8 and
    MicroProfile 2.0
    More about JSON-B:
    http://json-b.net

    View Slide

  19. @OMIHALYI
    Fault Tolerance

    Easy to add failure handling to REST calls
    with annotations
    – Circuit breaker, Timeout, Retry, Bulkheads
    – Fallback in case of unrecoverable failure
    – Asynchronous variants

    View Slide

  20. @OMIHALYI
    MESSAGING

    View Slide

  21. @OMIHALYI
    CDI events, really?

    Part of Java EE API already

    Easy to send and observe messages

    Similar to topics

    Is it enough? What about:
    – Sending events to other services
    – Message broker to decouple services
    – Transactions

    View Slide

  22. @OMIHALYI
    CDI events, really?
    What about:

    Sending events to other services – Important
    even in initial project stages

    Reliable delivery, Transactions – important in
    later stages, or not at all in some projects

    All can be extended using event handlers

    View Slide

  23. @OMIHALYI
    Events as an abstraction

    Transfer events to other services in an event
    handler
    – Using Payara CDI Event Bus (simple)
    – Using distributed queues (robust)
    – Using any message broker (flexible)

    Distribute incoming messages as events

    Start simple, extend to robust

    View Slide

  24. @OMIHALYI
    Java EE JCA connectors

    Message-driven beans, for any messaging infrastructure

    Connetors on Github for AWS, Azure, Kafka, MQTT
    @MessageDriven(activationConfig = { … })
    public class KafkaMDB implements KafkaListener {
    @OnRecord( topics={"my-topic"} )
    public void onMsg(ConsumerRecord record) {

    View Slide

  25. @OMIHALYI
    REST API
    CDI events
    JCA connector

    View Slide

  26. @OMIHALYI
    REST API
    CDI events
    JCA connector

    View Slide

  27. @OMIHALYI
    Or evolution to avoid
    refactoring
    event observer
    JCA
    connection
    observer
    MDB
    event

    View Slide

  28. @OMIHALYI
    Evolutionary architecture
    „An evolutionary architecture supports
    continual and incremental change as a first
    principle along multiple dimensions.“
    „Microservices meet this definition.“
    Neal Ford, Rebecca Parsons
    http://evolutionaryarchitecture.com/

    View Slide

  29. @OMIHALYI
    EXTERNAL CONFIGURATION

    View Slide

  30. @OMIHALYI
    REST API
    JCA connector
    Microprofile
    Configuration

    View Slide

  31. @OMIHALYI

    Standard config sources
    – Env. variables
    – System properties

    Pluggable sources
    – Database?, secrets?

    More sources in Payara Micro
    – Cluster-wide
    – Directory, secrets
    – Scoped (server, app, module)
    Microprofile Configuration
    @Inject
    @ConfigProperty(name =
    "myservice.url")
    URL myService;
    URL myService =
    ConfigProvider.getConfig()
    .getValue("myservice.url",
    URL.class);

    View Slide

  32. @OMIHALYI
    MONITORING

    View Slide

  33. @OMIHALYI
    Is there a free lunch?
    Microprofile provides a lot out of the box

    Metrics – monitoring data, statistics

    Health – problem detection and autorecovery

    Opentracing – connects related requests

    OpenAPI – docs for REST resources

    View Slide

  34. @OMIHALYI
    Monitoring Usecases

    Monitoring for application metrics

    Monitoring of failures to detect future problems

    Health check to restart service if not healthy

    Health (ready) check to detect when started and ready

    Tracing to combine logs and info about related
    service calls

    View Slide

  35. JAX-RS
    JCA connector
    Microprofile
    Configuration
    Microprofile Metrics, Health,
    Tracing, REST API docs
    Microprofile JWT
    Future?
    Microprofile
    Fault Tolerance

    View Slide

  36. @OMIHALYI
    More information

    https://microprofile.io/

    https://www.payara.fish/

    http://evolutionaryarchitecture.com/

    https://github.com/payara/Cloud-Connectors

    https://www.microprofile-ext.org/

    View Slide

  37. Thank You
    Not using the Payara Platform yet? Download the open
    source software: Payara Server or Payara Micro
    https://payara.fish/downloads
    Need support for the Payara Platform?
    https://payara.fish/support

    View Slide