
This video provides an overview of the entire course.
In a world of modern business models and digital products, the use of monolithic applications running on classical infrastructure is just not feasible anymore. Many organizations have already begun resorting to the elasticity of the cloud as it offers them greater agility, availability, resilience, and portability.
Learn about cloud-native applications
Understand the four phases of cloud-native application development
Understand the different challenges
Building cloud-native applications is challenging. Java EE 8 in combination with Eclipse MicroProfile APIs and other well-known open source components enables you to easily build hyperscale, elastic, loosely coupled, reliable, observable, and secure microservices.
Understand the Java EE 8 APIs for modern enterprise application development
Introduction to several new APIs and updates
Eclipse MicroProfile APIs address cross-cutting cloud-native concerns
Configure a Java EE 8 microservices project by adding dependencies with the provided scope and implementing a JAX-RS REST endpoint, then run it locally to verify the hello world response.
Every microservice is packaged, deployed, and run as a container. Docker is currently the predominant technology used to achieve this.
Write a Docker file and copy the WAR artifact
Build a Docker image and run microservices locally
Tune JVM to run in a containerized environment
Every microservice needs an ecosystem (database, service discovery, and edge service) to run in. It is crucial that this environment can be set up and run locally for short development cycles.
Write docker-compose.yml and add a database
Add a message queue to docker-compose.yml
Run all containers using Docker Compose
Manually scheduling and orchestrating multiple Docker containers is complex or even impossible. Kubernetes is a cluster scheduler and cluster orchestrator. It is the de facto standard for running cloud-native applications.
Deploy to local Kubernetes using Docker Compose
Convert Docker Compose to Kubernetes YAML with kompose
Deploy and run microservices on Kubernetes
When evolving a REST interface, you need to make sure you do not break existing consumers by versioning the endpoints. There are two approaches to accomplish this, and both can be implemented with JAX-RS: URL-based versioning and media type versioning.
URL-based versioning using sub resources
Add custom media type definitions
Use HTTP content negotiation to determine the version
In order to build a robust REST client, you should use the tolerant reader pattern to process the JSON responses: only read and extract the required fields and data, and ignore everything else. The different JSON-P APIs can be used to implement flexible JSON processing logic.
Use JSON-P and JAX-RS to read objects from remote clients
Use JSON Pointer to select values from JSON objects
Use JSON Patch to test for conditions on JSON payloads
Everything fails, all the time. When invoking remote endpoints you must make your logic robust and tolerant to failure by adding timeouts, retries, circuit breaker, or fallback routines. The MicroProfile Fault Tolerance APIs provide the means to do this.
Add the MicroProfile Fault Tolerance API dependency
Add @Timeout annotation to REST resource methods
Add @CircuitBreaker and @Fallback annotations to REST resource methods
For REST APIs to be easily consumable by clients, they should provide good documentation. The Open API Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs, which allows both humans and computers to discover and understand the capabilities of the service.
Add the MicroProfile Open API dependency
Add the Open API definition to package definition
Add the Open API definition to REST operations
When building microservice architectures, you should strive for loose coupling between the services by using asynchronous, message-driven communication. By using JMS in combination with JSON-P, you can implement flexible messaging logic easily.
Set up message queue infrastructure with Docker Compose
Add app server configuration for resource adapter and topic
Add JMS logic to send and receive JSON text messages
According to the 12-factor app principles, any configuration values should be stored in the environment and not in the application. Using MicroProfile Config APIs, we can easily access ENV variables, system properties or other config sources and inject the configuration properties using CDI.
Add the MicroProfile config dependency
Use @Inject @ConfigProperty to get config values
Add MicroProfile Config converters for custom types
Secrets are sensitive information and configuration properties and thus deserve special treatment. They should never be version controlled, and provided dynamically either via the ENV variable or file leveraging the Kubernetes secrets mechanism.
Store and provide sensitive information via .env files
Use Kubernetes secrets to store and provide secrets
Reference secrets via ENV variables or mounted secrets files
Scheduled tasks can easily be implemented using automatic or programmatic timer EJBs. Depending on the requirements, you may want to execute the scheduled tasks as a cluster singleton only. So you need to coordinate the instances and use a distributed data structure like a distributed lock.
Set up a clustered instance with Docker Compose
Create an automatic or programmatic Timer EJB
Synchronize a clustered timer with a distributed lock
The usage of stateful Java EE APIs (such as HTTP session, JSF, and JPA) is problematic in a cloud-native environment. This video will talk about the challenges of cloud-native state and persistence.
Session stickiness and session persistence do not work anymore
Persistence technology must be horizontally scalable and fault tolerant
Learn about several available persistence paradigms
In Java EE, the API for object relational mapping is JPA. It can be used to store relational as well as JSON data in a cloud-native databases such as CockroachDB by simply combining JPA with JSON-P.
Set up the database infrastructure with Docker Compose
Add app server configuration for the JPA data source
Add JPA persistence logic for relational and JSON data
Sometimes, relational object mapping using JPA is not a good fit for your data model and you may want to use a NoSQL data store. While there is no dedicated API, you can easily retrofit the functionality by using CDI, JSON-P, or JSON-B in combination with a native driver like the Mongo DB Java client.
Set up the database infrastructure with Docker Compose
Add dependencies and CDI integration for MongoDB client
Store document data using JSON-P, JSON-B, and JAX-RS
Cloud-native applications and microservices ought to be stateless. Unfortunately, some Java EE APIs such as JSF and even JPA are stateful. In order to use these in a cloud-native environment, they require that the state is replicated between the instances.
Mark the Java web app as <distributable/>
Use an HTTP session with JAX-RS
Use @SessionScoped beans with JSF
Sometimes, you may want to store and cache temporary data in your clustered microservice instances. Usually you want that all instances see the same state, so it needs to be replicated between them. The JCache API provides a HashMap-like programming API to access and use an in-memory data grid technology like Hazelcast.
Add the JCache API dependency
Configure the Hazelcast JCache provider
Store distributed state and data using the JCache API
In a highly distributed environment, good diagnosability is prime. The three cornerstones of the diagnosability triangle are logging, monitoring, and tracing. These are often complemented by reporting and altering to form the observability pentagon.
Learn why logging is important to analyse the system behaviour
Understand why monitoring is important for ops and business insights
Learn why tracing is required to understand and analyse request flows
In case of errors, you usually resort to log files to analyse the system behaviour. So having good, detailed, and structured logging is a cornerstone of good and easy diagnosability.
Define a suitable logging strategy
Choose a suitable logging framework
Configure the logging framework and add logging
Good and detailed telemetry data on technical as well as business metrics is another cornerstone of good diagnosability in a cloud-native environment in order to gain a better understanding of the performance and usage of a system.
Add the MicroProfile Metrics API dependency
Add custom metrics to JAX-RS resources
Collect metrics from endpoints using Prometheus
When running your microservices using a cluster scheduler such as Kubernetes, you have to provide endpoints to check whether your service is healthy and ready to serve requests.
Add the MicroProfile Health API dependency
Add health check implementations
Use the endpoint as a Kubernetes readiness probe
Tracing the requests in a microservice architecture is the third cornerstone of good diagnosability to be able to see and analyse the request flow.
Add the MicroProfile OpenTracing dependency
Configure request tracing for the used app server
Use MicroProfile OpenTracing on JAX-RS resources
With Java EE 8, there are some major changes regarding the Security API. It adds easy-to-use default authentication mechanisms (BASIC and Form) as well as the possibility for custom authentication mechanisms and pluggable identity store implementations.
Add BASIC authentication to the JAX-RS application
Secure the REST resource using Java EE Security annotations
Implement custom identity and group stores
With the MicroProfile JWT Authentication API, there is now the option to easily secure your REST API using a JSON Web Token (JWT) in combination with Java EE managed security.
Add the MicroProfile JWT Authentication dependency
Add JWT LoginConfig to the JAX-RS application
Secure the REST resource using Java EE security annotations
In a microservice architecture, securing your communication pathways is of utmost importance. Ideally, everything of communication should be encrypted. But key distribution and rotation can quickly become a burden. With Istio as a service mesh technology, you can easily implement mutual TLS between services without even having to modify them.
Create a Kubernetes cluster on GCP, Amazon, or Azure
Install the latest Istio version with mutual TLS enabled
Deploy your microservices
In a world of modern business models and digital products, the use of monolithic applications run classical infrastructure is just not feasible anymore. Many organizations have already begun resorting to the elasticity of the cloud as it offers them greater agility, availability, resilience, and portability. This video course is a one-stop solution for developers and architects, teaching them to understand the challenges faced in building cloud-native applications, using Java EE 8 and some additional well know open-source components and APIs. In combination, these APIs enable you to easily build hyperscale, elastic, loosely coupled, reliable, observable and secure microservices. Throughout this course, we address the different challenges you need to master to build truly cloud-native applications with Java EE. By the end of this course, you will be equipped with enough knowledge and practical experience to get your next cloud-native Java EE microservices up-and-running in no time, and with ease.
About the Author
Mario-Leander Reimer is a chief technologist for QAware GmbH. He is a senior Java developer with several years of experience in designing complex and large-scale system architectures. He continuously looks for innovations and ways to combine and apply state-of-the-art technology and open source software components in real-world customer projects. He studied computer science at Rosenheim and Staffordshire University. He teaches cloud computing as a part-time lecturer.