Mastering Microservices with Java: Build enterprise microservices with Spring Boot 2.0, Spring Cloud, and Angular, 3rd Edition

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Author(s): Sourabh Sharma

Language: English

Cover
Title Page
Copyright and Credits
Dedication
About Packt
Contributors
Table of Contents
Preface
Section 1: Fundamentals
Chapter 1: A Solution Approach
Services and SOA
Monolithic architecture overview
Limitations of monolithic architectures versus its solution with microservices architectures
Traditional monolithic design
Monolithic design with services
Microservices, nanoservices, teraservices, and serverless
One-dimension scalability
Release rollback in case of failure
Problems in adopting new technologies
Alignment with agile practices
Ease of development – could be done better
Nanoservices
Teraservices
Serverless
Deployment and maintenance
Microservices build pipeline
Deployment using a containerization engine such as Docker
Containers
Docker
Docker's architecture
Deployment
Summary
Chapter 2: Environment Setup
Spring Boot
Adding Spring Boot to our main project
REST
Writing the REST controller class
The @RestController annotation
The @RequestMapping annotation
The @RequestParam annotation
The @PathVariable annotation
Making a sample RESTapplication executable
An embedded web server
Maven build
Running the Maven build from IDE
Maven build from the Command Prompt
Testing using Postman
Some more positive test scenarios
Negative test scenarios
Summary
Further reading
Chapter 3: Domain-Driven Design
Domain-driven design (DDD) fundamentals
The fundamentals of DDD
Building blocks
Ubiquitous language
Multilayered architecture
Presentation layer
Application layer
Domain layer
Infrastructure layer
Artifacts of DDD
Entities
Value objects
Services
Aggregates
Repository
Factory
Modules
Strategic design and principles
Bounded context
Continuous integration
Context map
Shared kernel
Customer-supplier
Conformist
Anti-corruption layer
Separate ways
Open Host Service
Distillation
Sample domain service
Entity implementation
Repository implementation
Service implementation
Summary
Chapter 4: Implementing a Microservice
OTRS overview
Developing and implementing microservices
Restaurant microservice
OTRS implementation
Restaurant service implementation
Controller class
API versioning
Service classes
Repository classes
Entity classes
Booking and user services
Execution
Testing
Microservice deployment using containers
Installation and configuration
Docker Machine with 4 GB of memory
Building Docker images with Maven
Running Docker using Maven
Integration testing with Docker
Managing Docker containers
Executing Docker Compose
Summary
Section 2: Microservice Patterns, Security, and UI
Chapter 5: Microservice Patterns - Part 1
Service discovery and registration
Spring Cloud Netflix Eureka Server
Implementation
Spring Cloud Netflix Eureka client
Centralized configuration
Spring Cloud Config Server
Spring Cloud Config client
Execution and testing of the containerized OTRS app
Summary
References
Chapter 6: Microservice Patterns - Part 2
The overall architecture
Edge server and API gateway
Implementation
Demo execution
Circuit breaker
Implementing Hystrix's fallback method
Demo execution
Centralized monitoring
Enabling monitoring
Prometheus
Architecture
Integration with api-service
Grafana
Summary
Further reading
Chapter 7: Securing Microservices
Secure Socket Layer
Authentication and authorization
OAuth 2.0
Uses of OAuth
OAuth 2.0 specification – concise details
OAuth 2.0 roles
Resource owner
Resource server
Client
Authorization server
OAuth 2.0 client registration
Client types
Client profiles
Client identifier
Client authentication
OAuth 2.0 protocol endpoints
Authorization endpoint
Token endpoint
Redirection endpoint
OAuth 2.0 grant types
Authorization code grant
Implicit grant
Resource owner password credentials grant
Client credentials grant
OAuth implementation using Spring Security
Security microservice
API Gateway as a resource server
Authorization code grant
Using the access token to access the APIs
Implicit grant
Resource owner password credential grant
Client credentials grant
Summary
Further reading
Chapter 8: Consuming Services Using the Angular App
Setting up a UI application
Angular framework overview
MVC and MVVM
Angular architecture
Modules (NgModules)
Components
Services and dependency injection (DI)
Routing
Directives
Guard
Developing OTRS features
The home page
src/app.module.ts (AppModule)
src/app-routing.module.ts (the routing module)
src/rest.service.ts (the REST client service)
src/auth.guard.ts (Auth Guard)
app.component.ts (the root component)
app.component.html (the root component HTML template)
Restaurants list page
src/restaurants/restaurants.component.ts (the restaurants list script)
src/restaurants/restaurants.component.html (the restaurants list HTML template)
Searching for restaurants
Login page
login.component.html (login template)
login.component.ts
Restaurant details with a reservation option
restaurant.component.ts (the restaurant details and reservation page)
restaurant.component.html (restaurant details and reservation HTML template)
Reservation confirmation
Summary
Further reading
Section 3: Inter-Process Communication
Chapter 9: Inter-Process Communication Using REST
REST and inter-process communication
Load balanced calls and RestTemplate implementation
RestTemplate implementation
OpenFeign client implementation
Java 11 HTTPClient
Wrapping it up
Summary
Further reading
Chapter 10: Inter-Process Communication Using gRPC
An overview of gRPC
gRPC features
REST versus gRPC
Can I call gRPC server from UI apps?
gRPC framework overview
Protocol Buffer
The gRPC-based server
Basic setup
Service interface and implementation
The gRPC server
The gRPC-based client
Summary
Further reading
Chapter 11: Inter-Process Communication Using Events
An overview of the event-based microservice architecture
Responsive
Resilient
Elastic
Message driven
Implementing event-based microservices
Producing an event
Consuming the event
Summary
Further reading
Section 4: Common Problems and Best Practices
Chapter 12: Transaction Management
Design Iteration
First approach
Second approach
Two-phase commit (2PC)
Voting phase
Completion phase
Implementation
Distributed sagas and compensating transaction
Feral Concurrency Control
Distributed sagas
Routing slips
Distributed saga implementation
Saga reference implementations
Compensating transaction in the booking service
Booking service changes
Billing service changes
Summary
Further reading
Chapter 13: Service Orchestration
Choreography and orchestration
Choreography
Orchestration
Orchestration implementation with Netflix Conductor
High-level architecture
The Conductor client
Basic setup
Task definitions (blueprint of tasks)
WorkflowDef (blueprint of workflows)
The Conductor worker
Wiring input and output
Using Conductor system tasks such as DECISION
Starting workflow and providing input
Execution of sample workflow
Summary
Further reading
Chapter 14: Troubleshooting Guide
Logging and the ELK Stack
A brief overview
Elasticsearch
Logstash
Kibana
ELK Stack setup
Installing Elasticsearch
Installing Logstash
Installing Kibana
Running the ELK Stack using Docker Compose
Pushing logs to the ELK Stack
Tips for ELK Stack implementation
Using a correlation ID for service calls
Let's see how we can tackle this problem
Using Zipkin and Sleuth for tracking
Dependencies and versions
Cyclic dependencies and their impact
Analyzing dependencies while designing the system
Maintaining different versions
Let's explore more
Summary
Further reading
Chapter 15: Best Practices and Common Principles
Overview and mindset
Best practices and principles
Nanoservice, size, and monolithic
Continuous integration and continuous deployment (CI/CD)
System/end-to-end test automation
Self-monitoring and logging
A separate data store for each microservice
Transaction boundaries
Microservice frameworks and tools
Netflix Open Source Software (OSS)
Build – Nebula
Deployment and delivery – Spinnaker with Aminator
Service registration and discovery – Eureka
Service communication – Ribbon
Circuit breaker – Hystrix
Edge (proxy) server – Zuul
Operational monitoring – Atlas
Reliability monitoring service – Simian Army
AWS resource monitoring – Edda
On-host performance monitoring – Vector
Distributed configuration management – Archaius
Scheduler for Apache Mesos – Fenzo
Summary
Further reading
Chapter 16: Converting a Monolithic App to a Microservice-Based App
Do you need to migrate?
Cloud versus on-premise versus both cloud and on-premise
Cloud-only solution
On-premise only solution
Both cloud and on-premise solution
Approaches and keys to successful migration
Incremental migration
Process automation and tools setup
Pilot project
Standalone user interface applications
Migrating modules to microservices
How to accommodate a new functionality during migration
Summary
Further reading
Other Books You May Enjoy
Index