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. @OMIHALYI What is cloud ready? • Spring, Java EE /

    Jakarta EE, MicroProfile or Lagom • AWS, Azure or Openshift • SQL or NoSQL • REST or EJB
  2. 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
  3. @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
  4. @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
  5. @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
  6. @OMIHALYI REST services API (server) • JAX-RS endpoint public User

    getUser( Integer id) { return userById(id); }
  7. @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")
  8. @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")
  9. @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
  10. @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
  11. @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
  12. @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
  13. @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
  14. @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) { …
  15. @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/
  16. @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);
  17. @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
  18. @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
  19. JAX-RS JCA connector Microprofile Configuration Microprofile Metrics, Health, Tracing, REST

    API docs Microprofile JWT Future? Microprofile Fault Tolerance
  20. 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