Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building Microservivces with Java EE 8 and Microprofile

116 views

Published on

JCON 2018, Düsseldorf: Talk by Mario-Leander Reimer (@LeanderReimer, Principal Software Architect at QAware)

Abstract:
With Java EE 8 finally released and the latest additions to MicroProfile it is about time we have a closer look at how to develop modern and lightweight microservices with the latest API improvements. This session is a comprehensive guide showing how to develop state-of-the-art microservices with the latest Java EE 8 APIs. We will start by giving an overview of Java EE 8 and the latest API additions and improvements. Then we will implement, build and package our first working Java EE 8 microservice. We will then dive into the details of implementing synchronous RESTful web services, and learn about the specifics of data binding and content marshalling using the JSON-B and JSON-P APIs. We will see how to leverage the power of using the asynchronous APIs on the server as well as the client-side, and how Server-Sent-Events (SSE) can be used for push communication. Finally, we will cover some advanced topics such as validation, security, resiliency, health checks and diagnosability.

Published in: Data & Analytics
  • Be the first to comment

  • Be the first to like this

Building Microservivces with Java EE 8 and Microprofile

  1. 1. Mario-Leander Reimer, QAware GmbH mario-leander.reimer@qaware.de Building Microservices with Java EE 8 and Microprofile Düsseldorf, 09. Oktober 2018
  2. 2. Mario-Leander Reimer Principal Software Architect, QAware GmbH Contact Details Mail: mario-leander.reimer@qaware.de Twitter: @LeanderReimer Github: https://github.com/lreimer/ 09.10.2018 2 Developer && Architect 20+ years of experience #CloudNativeNerd Open Source Enthusiast Speaker && Author
  3. 3. Fork me on Github. https://github.com/lreimer/building-javaee-microservices
  4. 4. 4 loosely coupled stateless
  5. 5. 5 Components All Along the Software Lifecycle. DESIGN  Complexity unit  Data integrity unit  Coherent and cohesive features unit  Decoupled unit RUN  Release unit  Deployment unit  Runtime unit (crash, slow-down, access)  Scaling unit n:1 BUILD  Planning unit  Team assignment unit  Knowledge unit  Development unit  Integration unit 1:1
  6. 6. Essential Design Principles. 6 Design for Distribution: Containers; microservices; API driven development. Design for Configuration: One image, multiple environments. Design for Resiliency: Fault-tolerant and self-healing. Design for Elasticity: Scales dynamically and reacts to stimuli. Design for Delivery: Short roundtrips and automated provisioning. Design for Performance: Responsive; concurrent; resource efficient. Design for Automation: Automated Dev & Ops tasks. Design for Diagnosability: Cluster-wide logs, metrics and traces. Design for Security: Secure Endpoints, API-Gateways, E2E-Encryption
  7. 7. Microservice Blueprint with Java EE 8 and Microprofile 7
  8. 8. Overview of Java EE 8 APIs. CDI Extensions Web Fragments BeanValidation2.0 CDI 2.0 Managed Beans 1.0 JCA 1.7 JPA 2.2 JMS 2.0 JSP 2.3 EL 3.0 EJB 3.2 Batch 1.0 JSF 2.3 Interceptors 1.2 Mail 1.6 Common Annotations 1.3 JTA 1.2 JAX-WS 1.4 JAX-RS 2.1 Concurrency 1.0 JSON-P 1.1 JSON-B 1.0 WebSocket 1.1 JAPSIC 1.1 JACC 1.5 Security1.0 Servlet 4.0 JCache 1.0 8
  9. 9. Overview of Eclipse MicroProfile 2.0 APIs. 9see https://microprofile.io/presentations/
  10. 10. Cloud-ready runtimes suited for Java EE microservices. 10 … and many more.
  11. 11. @ApplicationPath("api") public class JAXRSConfiguration extends Application { } @Path("hello") public class HelloWorldResource { @GET @Produces(MediaType.APPLICATION_JSON) public JsonObject helloWorld() { String hostname = ofNullable(getenv("HOSTNAME")).orElse("localhost"); return Json.createObjectBuilder() .add("message", "Cloud Native Application Development with Java EE.") .add("hostname", hostname) .build(); } } Our first JAX-RS application and REST endpoint. 11
  12. 12. // JSON Patch is a web standard format for describing changes in a JSON document. // The JSON Patch media type is application/json-patch+json. [ { "op": "replace", "path": "/0/aString", "value": "Patched JSON-P." } ] JsonArray jsonArray = Json.createArrayBuilder() .add(Json.createObjectBuilder() .add("aString", "Hello Json-P.") .add("aInteger", 42) .add("aBoolean", false) .add("aNullValue", JsonValue.NULL)) .build(); JsonPatch jsonPatch = Json.createPatchBuilder(jsonPatchArray).build(); jsonPatch.apply(jsonArray) Use JSON-P for flexible parsing and processing. 12 Add: add a value into an object or array. Remove: remove a value from an object or array. Replace: replaces a value. Logically identical to using remove and then add. Copy: copy a value from one path to another by adding the value at a specified to another location. Move: moves a value from one place to another by removing from one location and adding to another. Test: tests for equality at a certain path for a certain value.
  13. 13. JsonbConfig jsonbConfig = new JsonbConfig() .withDateFormat("dd.MM.yyyy", Locale.GERMANY) .withFormatting(true) .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_DASHES) .withNullValues(true) .withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE); Jsonb jsonb = JsonbBuilder.newBuilder().withConfig(jsonbConfig).build(); String jsonBody = jsonb.toJson(jsonPojo); JsonbPojo jsonbPojo = jsonb.fromJson(jsonBody, JsonbPojo.class); @JsonbNillable public class JsonbPojo { @JsonbProperty(value = "greeting", nillable = true) private String message; @JsonbNumberFormat("#,##0.00") private Integer answerToEverything; @JsonbTransient private Object ignored; } Use JSON-B for easy data binding. 13
  14. 14. Building RESTful Web Services with Java EE 8 M.-Leander Reimer, Packt Publishing eBook or Video Discount Code: BRWSWJ50 Print Discount Code: BRWSWJ15
  15. 15. 09.10.2018 QAware 16
  16. 16. Mario-Leander Reimer mario-leander.reimer@qaware.de @LeanderReimer xing.com/companies/qawaregmbh linkedin.com/company/qaware-gmbh slideshare.net/qaware twitter.com/qaware youtube.com/qawaregmbh github.com/qaware

×