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

Building Cloud-native Applications with Java EE...

Building Cloud-native Applications with Java EE and Microprofile on Kubernetes

Cloud native applications are popular these days. They promise superior reliability and almost arbitrary scalability. They follow three key principles: they are built and composed as microservices. They are packaged and distributed in containers. The containers are executed dynamically in the cloud. But all this comes at a price: added complexity! Suddenly you need to consider important cloud native design principles such as service exposition, configuration, resilience, health checks, metrics, monitoring and tracing.

This session is a comprehensive hands-on guide showing how to develop state-of-the-art cloud native applications with Java EE 8 and MicroProfile APIs. We will start by giving a brief overview of the latest API additions and improvements. Then we will implement, build, package and deploy our first working microservice.

Next, we will dive into the details of implementing enterprise-ready microservices and cover topics such as synchronous and asynchronous service exposition via JAX-RS and JMS, data binding and content marshalling using the JSON-B 1.0 and JSON-P 1.1 APIs, handling state and persistence in a cloud native context, and addressing configuration, resiliency and diagnosability using MicroProfile APIs.

M.-Leander Reimer

October 03, 2018
Tweet

More Decks by M.-Leander Reimer

Other Decks in Programming

Transcript

  1. CDI Extensions Web Fragments Bean Validation 2.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 Security 1.0 Servlet 4.0 JCache 1.0
  2. @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(); } }
  3. FROM azul/zulu-openjdk:8u181 as builder RUN mkdir /tmp COPY . /tmp/

    WORKDIR /tmp RUN ./gradlew –no-daemon build FROM qaware/zulu-centos-payara-micro:8u181-5.183 COPY --from=builder /tmp/build/libs/javaee8-service.war /opt/payara/deployments/
  4. $ docker build -t javaee8-service:1.0.1 . $ docker run --name

    javaee8-service -d \ -p 8080:8080 javaee8-service:1.0.1 $ docker logs –f javaee8-service $ docker stop javaee8-service $ docker start javaee8-service $ docker tag javaee8-service:1.0.1 \ lreimer/ javaee8-service:1.0.1 $ docker push lreimer/javaee8-service:1.0.1
  5. version: '3' services: message-queue: ... postgres-db: ... javaee8-service: build: .

    image: javaee8-service:1.0.1 expose: - "5701" # the outbound Hazelcast port - "54327" # the multicast Hazelcast port ports: - ”8080:8080" # the HTTP endpoint depends_on: - message-queue - postgres-db $ docker-compose build $ docker-compose up –d --build $ docker-compose logs $ docker-compose down
  6. apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: io.kompose.service: javaee8-service name: javaee8-service

    spec: replicas: 2 template: metadata: labels: io.kompose.service: javaee8-service spec: containers: - image: javaee8-service:1.0 name: javaee8-service ports: - containerPort: 8080 restartPolicy: Always
  7. resources: # Define resources to help K8S scheduler # CPU

    is specified in units of cores # Memory is specified in units of bytes # required resources for a Pod to be started requests: memory: “256Mi" cpu: "250m" # the Pod will be restarted if limits are exceeded limits: memory: “640Mi" cpu: "500m"
  8. # container will receive requests if probe succeeds readinessProbe: httpGet:

    path: /api/application.wadl port: 8080 initialDelaySeconds: 30 timeoutSeconds: 5 # container will be killed if probe fails livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 90 timeoutSeconds: 10
  9. apiVersion: v1 kind: Service metadata: name: javaee8-service spec: # use

    NodePort here to be able to access the port on each node # use LoadBalancer for external load-balanced IP if supported type: LoadBalancer ports: - port: 8080 selector: io.kompose.service: javaee8-service