This example-rich tutorial shows how to design and manage large-scale Java applications as a collection of microservices. Starting with an overview of microservices from a Java EE perspective, you'll learn how to refactor your existing applications as microservices and build microservice-based applications from scratch. You'll power through practical tutorials as you call and connect microservices, understand what load balancing is, and use Netflix Hystrix for fault tolerance. You'll also master security and testing, as well as deploying to the cloud.
Part 1: Microservices Basics
1 Enterprise Java Microservices
1.1 Enterprise Java pitfalls
1.1.1 What is Enterprise Java?
1.1.2 Typical Enterprise Java Architecture
1.1.3 What is a Monolith?
1.1.4 Why Hate the Monolith?
1.2 Microservices and Distributed Architecture
1.2.1 Do One Thing Well
1.2.2 What is a Distributed Architecture?
1.2.3 Why should I care about being Distributed?
1.2.4 What can be done to assist in developing Microservices?
1.2.5 Product over Project
1.2.6 Continuous Integration and Delivery
1.3 Patterns for migration to microservices
1.3.1 Domain Driven Design
1.3.2 Big Bang Pattern
1.3.3 Strangler Pattern
1.3.4 Hybrid Pattern
1.4 What are Enterprise Java Microservices?
1.4.1 Why Enterprise Java is a good fit for Microservices
2 Developing a Simple RESTFul Microservice
2.1 Cayambe Monolith
2.2 New Administration Site
2.2.1 Use Cases
2.2.2 Architecture of the Application
2.2.3 Creating RESTFul endpoints with JAX-RS
2.2.4 Run it
3 Just enough Application Server for Microservices
3.1 Just enough Application Server
3.1.1 What does it mean?
3.1.2 What are the benefits?
3.1.3 Eclipse MicroProfile
3.2 Choosing Just enough Application Server
3.2.1 Beach Vacation example application
3.2.2 Dropwizard - The Original Opinionated Microservice runtime
3.2.3 Payara Micro - Slimmed Java EE App Server in a Jar
3.2.4 Spring Boot - Opinionated Spring Microservices
3.2.5 Thorntail - The Most Flexible JeAS Runtime
3.2.6 How do they compare?
4 Microservice Testing
4.1 What type of Testing do we need?
4.2 Unit Testing
4.3 Integration Testing
4.4 Consumer Driven Contract Testing
4.5 Additional Reading
4.6 Additional Exercises
5 Cloud Native Development
5.1 What is Cloud anyway?
5.1.1 Service Models
5.1.2 Cloud Native Development
5.2 Deploying to the Cloud
5.2.1 Starting Minishift
5.2.2 Microservice Cloud deployment
5.3 Testing in the Cloud
5.4 Additional Exercises
Part 2: Implementing Enterprise Java Microservices
6 Consuming Microservices
6.1 Consuming a Microservice with a Java Client Library
6.1.2 Apache HttpClient
6.2 Consuming a Microservice with a JAX-RS Client Library
6.2.1 JAX-RS Client
6.2.2 RESTEasy Client
7 Discovering Microservices for Consumption
7.1 Why does a Microservice need to be discovered?
7.1.1 What is Service Discovery?
7.1.2 What are the benefits of Service Discovery and a Registry?
7.1.3 Stateless vs Stateful Microservices
7.1.4 What is Netflix Ribbon?
7.2 Registering a Microservice with Thorntail
7.2.1 Thorntail’s Topologies
7.2.2 Registering a Microservice with a Topology
7.3 Consuming a Registered Microservice with Thorntail
7.3.1 Service Lookup with Netflix Ribbon
7.3.2 Service Lookup with RESTEasy Client
8 Strategies for Fault Tolerance and Monitoring
8.1 Microservice Failures in a Distributed Architecture
8.1.1 Network Failures
8.2 Mitigating Against Failures
8.2.1 What is Hystrix?
8.2.2 Circuit Breakers
8.2.5 Request Caching
8.2.6 Putting it all together
8.2.7 Hystrix Dashboard
8.3 Adding Hystrix to our Payment Microservice
8.3.1 Hystrix with RESTEasy Client
8.3.2 Hystrix with Ribbon Client
9 Securing a Microservice
9.1 Importance of Securing Microservice
9.1.1 Why is Security Important?
9.1.2 What does it need to solve?
9.1.3 What is Keycloak?
9.1.4 Setting up Keycloak
9.2 Securing Stripe Microservice
9.2.1 Configuring Keycloak
9.2.2 Securing the Stripe Resource
9.2.3 Authenticating in Payment Resource
9.2.4 Testing our Secured Microservice
9.3 Capturing User Authentication
9.3.1 Configuring Keycloak
9.3.2 Securing Category Deletion
9.3.3 Authenticating the User in a UI
9.3.4 Testing it all works
10 Architecting a Microservice Hybrid
10.1 The Cayambe "Monolith"
10.1.1 Running Cayambe "Monolith"
10.2 Cayambe Hybrid - "Monolith" with Microservices
10.2.1 Integrating Payment Microservice
10.2.2 Integrating Admin Microservice
10.2.3 New Administration UI
10.2.4 Cayambe Hybrid Summary
10.3 Deploying everything to a Hybrid Cloud
10.3.4 Stripe Microservice
10.3.5 Payment Microservice
10.3.6 Cayambe Hybrid
10.3.7 Admin UI
11 Data Streaming with Apache Kafka
11.1 What can Apache Kafka do for me?
11.1.1 Data Streaming
11.1.2 Apache Kafka
11.2 Simplifying our "Monolith" architecture with streaming
11.3 Deploy and Utilize Kafka for Data Streaming
11.3.1 Kafka on OpenShift
11.3.2 Admin microservice
11.3.3 Kafka Consumer
11.4 Additional Exercises
Appendix A: A Spring Boot Microservices
A.1 Anatomy of a Spring Boot project
A.1.1 Examining a newly initialized Spring Boot project
A.2 Spring Boot Starter Dependencies
A.2.1 Using starter dependencies
A.3 Developing a Spring Boot Application
A.3.1 Focusing on application functionality
A.4 Spring Boot Testing
A.4.1 Mocking Spring MVC
About the Technology
Over time, enterprise-grade Java applications can become giant hulking beasts of intertwined code, bloated with third-party libraries, and vulnerable to total collapse when a single part fails. It doesn't have to be that way! Microservices break down a large application into smaller components, each interacting with each other to create a united whole. As each component can start, stop, and scale independently, so the whole system benefits from better fault-tolerance and resilience. Equally-important, separating the application into smaller independent services makes it substantially easier to efficiently manage the development and incremental improvement of your system.
- The microservices mental model
- Fault tolerance with Netflix Hystrix
- Securing your microservices
- Deploying to the cloud
About the reader
This book is for Java developers familiar with distributed n-tier application architecture.