Pro Cloud Native Java EE Apps: DevOps with MicroProfile, Jakarta EE 10 APIs, and Kubernetes
1484288998, 9781484288993
This professional guide to Java-based cloud native apps DevOps dives deeper into building and deploying production ready
143
39
7MB
English
Pages 380
[369]
Year 2022
Report DMCA / Copyright
DOWNLOAD PDF FILE
Table of contents :
Table of Contents
About the Authors
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: The Theory of Jakarta EE and MicroProfile
What Is a Specification?
Java EE Release History
Java 2 Platform, Enterprise Edition (J2EE 1.2)
Java 2 Platform, Enterprise Edition (J2EE 1.3)
Java 2 Platform, Enterprise Edition (J2EE 1.4)
Java Platform, Enterprise Edition (Java EE) 5
Java Platform, Enterprise Edition (Java EE) 6
Java Platform, Enterprise Edition (Java EE) 7
Java Platform, Enterprise Edition (Java EE) 8
From Java EE to Jakarta EE
Transfer API and Implementation Code
Transfer Test Compatibility Kit (TCK) Code, New Specification Process
Refactor API Package Name, Transfer and Update Specification Documents
Jakarta EE 10 and Beyond
Jakarta EE and Eclipse MicroProfile
OpenTracing
OpenAPI
Rest Client
Config
Fault Tolerance
Metrics
JWT Auth/Propagation
Health
CDI
JSON-P
JAX-RS
JSON-B
Annotations
Jakarta EE and the Spring Framework
Why Jakarta EE?
Standardization
Openness
Stability
Ease of Development
Portability
Pick and Choose – Tank or Pistol
Amazing Documentation
Summary
Chapter 2: Enterprise Java, Microservices, and the Cloud
The Birth of Java 2 Enterprise Edition (J2EE)
Monoliths
Development Speed
Simpler to Onboard
Simplified Testing
Simplified Deployment
Simplified Scaling
A Changing Development Landscape
Rise of Internet-Connected Devices
General Shift in Software Consumption
Rise in Popularity of Web Applications
Rise in Popularity of Third-Party Hosted Infrastructure
Rise in Popularity of the REST Architecture
Rise of the API Ecosystem
Lower Cost of Outsourcing Infrastructure
Boom in Competitive Firms
The Rise of Microservices
Managing Complexity Through Decomposition
Easier to Maintain
Faster Development
Scalability
Resilience
Easier Adoption of New Technologies
Cloud-Native Development
Public Cloud
Private Cloud
Hybrid Cloud
The 12-Factor Application
Codebase
Dependencies
Configuration
Backing Services
Build, Release, Run
Processes
Port Binding
Concurrency
Disposability
Dev/Prod Parity
Logs
Admin Processes
Containers and the Cloud
Enterprise Java and Cloud-Native Development
Summary
Chapter 3: Enterprise Applications – Architecture
Enterprise Applications – What Are They?
Dependency Management
RESTful Web Service
Data Persistence
Ancillary Cloud Features
Health Check
Fault Tolerance
Configuration
Metrics
Introduction to JWallet
JWallet – Setup
A Note on IDE
Hello, World!
Application Architecture Overview
JWallet
Testing
Summary
Chapter 4: Managing Dependencies with CDI
An Overview of CDI in Jakarta EE 10
Key Features of CDI
Typesafe Dependency Resolution Mechanism
Well-Defined Lifecycle Contexts
Integration with the Web Tier
Interceptors
Events
An SPI for Creating Extensions
CDI Activation
Bean Discovery Modes
None
Annotated
All
The beans.xml File
The CDI Container
Beans and Contextual Instances
What Is a CDI Bean?
CDI Bean Types
Resolution by Type
Resolution by Name and Qualifier
Resolution by Name
CDI Beans and Contextual Instances
Scopes and Contexts
Bean Proxying
Built-In Scopes
@ApplicationScoped
@RequestScoped
@SessionScoped
@ConversationScoped
@Dependent Pseudo-Scope
Injection Points
Field Injection Point
Constructor Injection
Method Injection
Jakarta Enterprise Beans
Qualifiers
@Default Qualifier
Other Built-In Qualifiers
CDI Producers
Producer Fields
Qualifying Producer Fields
Producer Methods
CDI Producers – Caveats
Stereotypes
Lifecycle Callbacks
@PostConstruct
@PreDestroy
CDI Interceptors
The Interceptor Annotation
The Interceptor Bean
Using Stereotypes with Interceptors
CDI Decorators
CDI Events
The Event Object
The Event Observer
Asynchronous Events
Transactional Observers
Qualifying Events
Event Metadata
Conditional Observer Methods
Summary
Chapter 5: Persistence with Jakarta EE Persistence
JPA at a Glance
The JPA Runtime
Data Modelling
Data Persistence
Querying
Data Modelling with JPA
The Simplest Unit
Primary Key Generation
Id Generation
AUTO
TABLE
SEQUENCE
IDENTITY
Customizing Columns
Mapping Temporal Types
Mapping Large Objects
Simple Field Types
Lazy Fetching
Mapping Enums
Transient Fields
Field and Property Access
Organizing with Inheritance
Embeddables
Relationships
Single-Valued Relationships
Many-to-One
One-to-One
Collection-Valued Relationships
One-to-Many
Many-to-Many
Lazy Fetching
Collections of Simple Types
Maps
Data Persistence
Persistence Unit
Persistence Context
Transactions
EntityManager
Persisting Entities
Injecting the EntityManager
Persisting Data
Transaction Rollback
Updating and Removing Data
Cascading Operations
Callback Methods
Entity Listeners
Querying Data
Finding by Primary Key
Jakarta Persistence Query Language (JPQL)
The Structure of JPQL
Selecting with Select
The From Clause
The WHERE Clause
Aggregate Queries
Executing Queries
Dynamic Queries
Named Queries
Passing Parameters
Criteria API
Summary
Chapter 6: REST with Jakarta EE REST API
Modelling REST Services
The User Resource
Jakarta REST Resources
The Root Resource
A Jakarta REST Resource
HTTP Methods
@POST
Message Body Readers
Message Body Writers
Validating Resources
@GET
@PathParam
@BeanParam and @QueryParam
@DefaultValue
@PUT
@DELETE
The Response Object
Exception Mappers
The Jakarta REST Client
The MicroProfile REST Client
Summary
Chapter 7: Managing Configurations
What Is the Config Specification?
Config Sources
Custom Config Sources
Converters
Automatic Converters
Custom Converters
Config Value
The Config Bean
Direct Injection of Target Type
Optional Injection
Provider Injection
Supplier Injection
The ConfigValue Metadata
Summary
Chapter 8: Resilience with Fault Tolerance API
Fault Tolerance
Fallback
Timeout
Retry
Circuit Breaker
Closed
Open
Half-Open
Asynchronous
Bulkhead
Semaphore Style
Thread Pool Style
Configuring Fault Tolerance with Config
Individual Overrides
Global Parameter Overrides
Summary
Chapter 9: Keeping Count with Metrics
The Structure
Base Metrics
Application Metrics
Vendor Metrics
Metrics Data Format
The Metrics Registry
Using Metrics
Annotations
@Counted
@ConcurrentGauge
@Gauge
@Metered
@SimplyTimed
@Timed
Injecting Metrics
Using Histogram Metric
Manual Registration of Metrics
Metrics Metadata
Other MicroProfile Spec Metrics
CDI Stereotypes and Metrics
Summary
Chapter 10: Taking a Pulse with Heal Check
Health vs. Metrics
Health API Structure
The HealthCheck Interface
The HealthCheckResponse
Health and CDI
Health Check Qualifiers
@Readiness
@Liveness
@Startup
Combining Health Checks
Producing Health Checks
Summary
Chapter 11: Security with JWT
Token-Based Authentication
The Header
The Claims (or Body)
The Signature
The MicroProfile JWT
MicroProfile JWT Security Process
Authenticate the Client
Providing the Public Key
Authorization
Security Context Propagation
MicroProfile JWT Usage
Getting Information from Tokens
JsonWebToken
Injecting into Raw Types and ClaimValue
MicroProfile JWT and the SecurityContext
Summary
Chapter 12: Testing with TestContainers
The Theory of Application Testing
Types of Tests
Unit Tests
Integration Tests
Functional Tests
Performance Tests
Smoke Tests
Other Tests
Principles of Testing
Testing Shows the Presence of Defects, Not Their Absence
Exhaustive Testing Is Impossible
Early Testing Saves Time and Money
Defects Cluster
Beware of the Pesticide Principle
Testing Is Contextual
Absence of Errors Is a Fallacy
Testing in Jakarta EE
Unit-Testing Jakarta EE Components
JUnit
Mockito
Integration Testing in Jakarta EE
Summary
Chapter 13: Jakarta EE Application Deployment Considerations
Production Readiness
Business Requirements Met?
Test Requirements
CI/CD Pipelines
Further Development Strategy
Security
Jakarta EE Deployment
Choosing a Runtime
Popularity of the Runtime
License Considerations
Support
Additional Features
Existing Knowledge
Other Considerations
Containerization
Cloud Deployment
Database
Security
Deploying a Monolith
Application Maintenance
Use the Platform
Have a Package Standard
Choose a Runtime Carefully
Avoid Excessive Use of Third-Party Libraries
Keep Things Simple
Have a Convention
Document Excessively
Build and Dependency Management
Summary
Chapter 14: Cloud-Native Jakarta EE Monoliths to Microservices
Monoliths
Pros of the Monolith Architecture
Simple to Develop
Easier to Test
Easier to Deploy
Easier to Debug
Reusability
Easy to Add New Developers
Easier Application Evolution
Easy to Scale
Challenges of the Monolith
Single Point of Failure
Slow to Adopt New Technologies
Full Redeployment
Grown Complexity
Microservices
Considerations for Adoption or Migration
Application Insights
Availability of Technical Knowledge
Onboarding New Developers
Deployment Costs
Keeping the End Goal in Mind
Migrating a Monolith
Single Responsibility Principle
Organize Around the Business Domain
Create Libraries for Common Functionality
Deployable Unit
Communicate via REST
Separate Security Contexts
Sample Migrated Application
Summary
Index