You are previewing Mastering Microservices with Java.
O'Reilly logo
Mastering Microservices with Java

Book Description

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

About This Book

  • Build, deploy, and test microservices from scratch with ease

  • Design and implement sample projects using domain-driven design

  • Confidently resolve the issues faced during development and deployment

  • Who This Book Is For

    If you are a Java developer who is familiar with the microservices architecture and now wants to take a deeper dive into effectively implementing microservices at an enterprise level, then this book is for you. 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

  • Deploy and test microservices

  • Troubleshoot and debug the issues faced during development

  • Consume microservices using a JavaScript web application

  • Learning best practices and common principals about microservices

  • In Detail

    With the introduction of the cloud, enterprise application development moved from monolithic applications to small lightweight process-driven components called microservices. 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 it effectively using REST Java clients and other tools. Finally, we’ll show you the best practices and common principals of microservice design and you’ll learn to troubleshoot and debug the issues faced during development.

    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. It gives you the complete lifecycle of enterprise app development from designing and developing to deploying, testing, and security. Each topic is explained and placed in context, and for the more inquisitive, there are more details of the concepts used.

    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 If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Mastering Microservices with Java
      1. Table of Contents
      2. Mastering Microservices with Java
      3. Credits
      4. About the Author
      5. About the Reviewer
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. 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
      8. 1. A Solution Approach
        1. Evolution of µServices
        2. Monolithic architecture overview
        3. Limitation of monolithic architecture versus its solution with µServices
          1. One dimension scalability
          2. Release rollback in case of failure
          3. Problems in adopting new technologies
          4. Alignment with Agile practices
          5. Ease of development – could be done better
          6. Microservices build pipeline
          7. Deployment using a container such as Docker
            1. Containers
            2. Docker
            3. Docker's architecture
              1. Docker image
            4. Docker container
            5. Deployment
        4. Summary
      9. 2. Setting Up the Development Environment
        1. Spring Boot configuration
          1. Spring Boot overview
          2. Adding Spring Boot to the rest sample
          3. Adding a Jetty-embedded server
        2. Sample REST program
          1. Writing the REST controller class
            1. @RestController
            2. @RequestMapping
            3. @RequestParam
            4. @PathVariable
          2. Making a sample REST app executable
        3. Setting up the application build
          1. Running the Maven tool
          2. Executing with the Java command
        4. REST API testing using the Postman Chrome extension
          1. Some more positive test scenarios
          2. Negative test scenarios
        5. NetBeans IDE installation and setup
        6. References
        7. Summary
      10. 3. Domain-Driven Design
        1. Domain-driven design fundamentals
        2. Building blocks
          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. Frequently asked questions
            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
      11. 4. Implementing a Microservice
        1. OTRS overview
        2. Developing and implementing µServices
          1. Restaurant µService
            1. Controller class
              1. API versioning
            2. Service classes
            3. Repository classes
            4. Entity classes
          2. Booking and user services
          3. Registration and Discovery service (Eureka service)
          4. Execution
        3. Testing
        4. References
        5. Summary
      12. 5. Deployment and Testing
        1. An overview of microservice architecture using Netflix OSS
        2. Load balancing
          1. Client-side load balancing
          2. Server-side load balancing
        3. Circuit breaker and monitoring
          1. Using Hystrix's fallback methods
          2. Monitoring
          3. Setting up the Hystrix Dashboard
          4. Setting up Turbine
        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
      13. 6. 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
                1. Confidential client type
                2. Public client type
                3. Web application
                4. User agent-based application
                5. Native application
              2. Client identifier
              3. 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
                1. Authorization code requests and responses
              2. Implicit grant
                1. Implicit grant requests and responses
              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
      14. 7. Consuming Services Using a Microservice Web App
        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 app
        4. Summary
      15. 8. Best Practices and Common Principles
        1. Overview and mindset
        2. Best practices and principals
          1. Nanoservice (not recommended), 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
      16. 9. Troubleshooting Guide
        1. Logging and 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. Tips for ELK stack implementation
        2. Use of correlation ID for service calls
          1. Let's see how we can tackle this problem
        3. Dependencies and versions
          1. Cyclic dependencies and their impact
            1. It needs to be analyzed while designing the system
          2. Maintaining different versions
          3. Let's explore more
        4. References
        5. Summary
      17. Index