O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Microservices with Java 9 - Second Edition

Book Description

Master the art of implementing scalable microservices in your production environment with ease

About This Book

  • Use domain-driven design to build microservices
  • Use Spring Cloud to use Service Discovery and Registeration
  • Use Kafka, Avro and Spring Streams for implementing event based microservices

Who This Book Is For

This book is for Java developers who are familiar with the microservices architecture and now wants to take a deeper dive into effectively implementing microservices at an enterprise level. A reasonable knowledge level and understanding of core microservice elements and applications is expected.

What You Will Learn

  • Use domain-driven design to design and implement microservices
  • Secure microservices using Spring Security
  • Learn to develop REST service development
  • Deploy and test microservices
  • Troubleshoot and debug the issues faced during development
  • Learning best practices and common principals about microservices

In Detail

Microservices are the next big thing in designing scalable, easy-to-maintain applications. It not only makes app development easier, but also offers great flexibility to utilize various resources optimally. If you want to build an enterprise-ready implementation of the microservices architecture, then this is the book for you!

Starting off by understanding the core concepts and framework, you will then focus on the high-level design of large software projects. You will gradually move on to setting up the development environment and configuring it before implementing continuous integration to deploy your microservice architecture. Using Spring security, you will secure microservices and test them effectively using REST Java clients and other tools like RxJava 2.0. We'll show you the best patterns, practices and common principals of microservice design and you'll learn to troubleshoot and debug the issues faced during development. We'll show you how to design and implement reactive microservices. Finally, we’ll show you how to migrate a monolithic application to microservices based application.

By the end of the book, you will know how to build smaller, lighter, and faster services that can be implemented easily in a production environment.

Style and approach

This book starts from the basics, including environment setup and provides easy-to-follow steps to implement the sample project using microservices.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. A Solution Approach
    1. Evolution of microservices
    2. Monolithic architecture overview
    3. Limitation of monolithic architecture versus its solution with microservices
      1. Traditional monolithic design
      2. Monolithic design with services
      3. Services design
      4. One dimension scalability
      5. Release rollback in case of failure
      6. Problems in adopting new technologies
      7. Alignment with Agile practices
      8. Ease of development – could be done better
      9. Microservices build pipeline
      10. Deployment using a container such as Docker
        1. Containers
        2. Docker
          1. Docker's architecture
    4. Deployment
    5. Summary
  3. Setting Up the Development Environment
    1. NetBeans IDE installation and setup
    2. Spring Boot configuration
      1. Spring Boot overview
      2. Adding Spring Boot to our main project
    3. Sample REST program
      1. Writing the REST controller class
        1. The @RestController annotation
        2. The @RequestMapping annotation
        3. The @RequestParam annotation
        4. The @PathVariable annotation
      2. Making a sample REST application executable
      3. Adding a Jetty-embedded server
    4. Setting up the application build
      1. Running the Maven tool
      2. Executing with the Java command
    5. REST API testing using the Postman Chrome extension
      1. Some more positive test scenarios
      2. Negative test scenarios
    6. Summary
  4. Domain-Driven Design
    1. Domain-driven design fundamentals
    2. Fundamentals of DDD
      1. Ubiquitous language
      2. Multilayered architecture
        1. Presentation layer
        2. Application layer
        3. Domain layer
        4. Infrastructure layer
      3. Artifacts of domain-driven design
        1. Entities
        2. Value objects
          1. FAQs
        3. Services
        4. Aggregates
        5. Repository
        6. Factory
        7. Modules
    3. Strategic design and principles
      1. Bounded context
      2. Continuous integration
      3. Context map
        1. Shared kernel
        2. Customer-supplier
        3. Conformist
        4. Anticorruption layer
        5. Separate ways
        6. Open Host Service
        7. Distillation
    4. Sample domain service
      1. Entity implementation
      2. Repository implementation
      3. Service implementation
    5. Summary
  5. Implementing a Microservice
    1. OTRS overview
    2. Developing and implementing microservices
      1. Restaurant microservice
      2. OTRS implementation
        1. Controller class
          1. API versioning
        2. Service classes
        3. Repository classes
        4. Entity classes
      3. Registration and discovery service (Eureka service)
    3. Eureka client
      1. Booking and user services
      2. Execution
    4. Testing
    5. References
    6. Summary
  6. Deployment and Testing
    1. Mandatory services for good microservices
      1. Service discovery and registration
      2. Edge servers
      3. Load balancing
      4. Circuit breakers
      5. Monitoring
    2. An overview of microservice architecture using Netflix OSS
      1. Load balancing
      2. Server-side load balancing
      3. Client-side load balancing
      4. Circuit breakers and monitoring
      5. Using Hystrix's fallback methods
      6. Monitoring
        1. Setting up the Hystrix dashboard
      7. Creating Turbine services
    3. Building and running the OTRS application
    4. Microservice deployment using containers
      1. Installation and configuration
        1. Docker machine with 4 GB
        2. Building Docker images with Maven
        3. Running Docker using Maven
        4. Integration testing with Docker
        5. Pushing the image to a registry
        6. Managing Docker containers
    5. References
    6. Summary
  7. Reactive Microservices
    1. An overview of the reactive microservice architecture
      1. Responsive
      2. Resilient
      3. Elastic
      4. Message driven
    2. Implementing reactive microservices
      1. Producing an event
      2. Consuming the event
    3. References
    4. Summary
  8. Securing Microservices
    1. Enabling Secure Socket Layer
    2. Authentication and authorization
      1. OAuth 2.0
        1. Usage of OAuth
      2. OAuth 2.0 specification - concise details
        1. OAuth 2.0 roles
          1. Resource owner
          2. Resource server
          3. Client
          4. Authorization server
        2. OAuth 2.0 client registration
          1. Client types
          2. Client profiles
          3. Client identifier
          4. Client authentication
        3. OAuth 2.0 protocol endpoints
          1. Authorization endpoint
          2. Token endpoint
          3. Redirection endpoint
        4. OAuth 2.0 grant types
          1. Authorization code grant
          2. Implicit grant
          3. Resource owner password credentials grant
          4. Client credentials grant
    3. OAuth implementation using Spring Security
      1. Authorization code grant
      2. Implicit grant
      3. Resource owner password credential grant
      4. Client credentials grant
    4. References
    5. Summary
  9. Consuming Services Using a Microservice Web Application
    1. AngularJS framework overview
      1. MVC
      2. MVVM
      3. Modules
      4. Providers and services
      5. Scopes
      6. Controllers
      7. Filters
      8. Directives
      9. UI-Router
    2. Development of OTRS features
      1. Home page/restaurant list page
        1. index.html
        2. app.js
        3. restaurants.js
        4. restaurants.html
      2. Search restaurants
      3. Restaurant details with reservation option
        1. restaurant.html
      4. Login page
        1. login.html
        2. login.js
      5. Reservation confirmation
    3. Setting up the web application
    4. References
    5. Summary
  10. Best Practices and Common Principles
    1. Overview and mindset
    2. Best practices and principles
      1. Nanoservice, size, and monolithic
      2. Continuous integration and deployment
      3. System/end-to-end test automation
      4. Self-monitoring and logging
      5. A separate data store for each microservice
      6. Transaction boundaries
    3. Microservices frameworks and tools
      1. Netflix Open Source Software (OSS)
        1. Build - Nebula
        2. Deployment and delivery - Spinnaker with Aminator
        3. Service registration and discovery - Eureka
        4. Service communication - Ribbon
        5. Circuit breaker - Hystrix
        6. Edge (proxy) server - Zuul
        7. Operational monitoring - Atlas
        8. Reliability monitoring service - Simian Army
        9. AWS resource monitoring - Edda
        10. On-host performance monitoring - Vector
        11. Distributed configuration management - Archaius
        12. Scheduler for Apache Mesos - Fenzo
        13. Cost and cloud utilization - Ice
        14. Other security tools - Scumblr and FIDO
          1. Scumblr
          2. Fully Integrated Defence Operation (FIDO)
    4. References
    5. Summary
  11. Troubleshooting Guide
    1. Logging and the ELK stack
      1. A brief overview
        1. Elasticsearch
        2. Logstash
        3. Kibana
      2. ELK stack setup
        1. Installing Elasticsearch
        2. Installing Logstash
        3. Installing Kibana
          1. Running the ELK stack using Docker Compose
          2. Pushing logs to the ELK stack
          3. Tips for ELK stack implementation
    2. Use of correlation ID for service calls
      1. Let's see how we can tackle this problem
        1. Use of Zipkin and Sleuth for tracking
    3. Dependencies and versions
      1. Cyclic dependencies and their impact
        1. Analyzing dependencies while designing the system
      2. Maintaining different versions
      3. Let's explore more
    4. References
    5. Summary
  12. Migrating a Monolithic Application to Microservice-Based Application
    1. Do you need to migrate?
      1. Cloud versus on-premise versus both cloud and on-premise
        1. Cloud only solution
        2. On-premise only solution
        3. Both cloud and on-premise solution
    2. Approaches and keys to successful migration
      1. Incremental migration
      2. Process automation and tools setup
      3. Pilot project
      4. Standalone user interface applications
      5. Migrating modules to microservices
      6. How to accommodate a new functionality during migration
    3. References
    4. Summary