
Mastering Microservices with Java 9 Second Edition Build domain-driven microservice-based applications with Spring, Spring Cloud, and Angular Sourabh Sharma BIRMINGHAM - MUMBAI Mastering Microservices with Java 9 Second Edition Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2016 Second edition: December 2017 Production reference: 1051217 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78728-144-8 www.packtpub.com Credits Author Copy Editor Safis Editing Sourabh Sharma Reviewer Project Coordinator Guido Grazioli Vaidehi Sawant Commissioning Editor Proofreader Aaron Lazar Safis Editing Acquisition Editor Indexer Denim Pinto Aishwarya Gangawane Content Development Editor Production Coordinator Zeeyan Pinheiro Melwyn D'sa Technical Editor Romy Dias About the Author Sourabh Sharma has over 15 years of experience in product/application development. His expertise lies in designing, developing, deploying, and testing N-tier web applications and leading teams. He loves to troubleshoot complex problems and look for the best solutions. Throughout his career, he has successfully delivered various on-premise and cloud applications/products to some of the fortune 500 companies that has amazed stakeholders, including happy satisfied customers. Sourabh believes in the continuous process of learning and has been continuously updating his skill set —from standalone application development to microservices development, from JDK 1.2 to Java 9, from IE 5 dependent frontend code to cross-browser development, and from on-premise deployment to cloud deployment. He has effectively managed delivering single products to bouquets of applications. About the Reviewer Guido Grazioli has worked as an application developer, software architect, and systems integrator for a wide variety of business applications across several domains. He is a hybrid software engineer with deep knowledge of the Java platform and tooling as well as Linux systems. He is particularly interested in SOAs, EIPs, continuous integration and delivery, and service orchestration in the cloud. www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. https://www.packtpub.com/mapt Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1787 281442. If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface What this book covers What you need for this book Who this book is for Conventions Reader feedback Customer support Downloading the example code Errata Piracy Questions 1. A Solution Approach Evolution of microservices Monolithic architecture overview Limitation of monolithic architecture versus its solution with microservices Traditional monolithic design Monolithic design with services Services design 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 Microservices build pipeline Deployment using a container such as Docker Containers Docker Docker's architecture Deployment Summary 2. Setting Up the Development Environment NetBeans IDE installation and setup Spring Boot configuration Spring Boot overview Adding Spring Boot to our main project Sample REST program Writing the REST controller class The @RestController annotation The @RequestMapping annotation The @RequestParam annotation The @PathVariable annotation Making a sample REST application executable Adding a Jetty-embedded server Setting up the application build Running the Maven tool Executing with the Java command REST API testing using the Postman Chrome extension Some more positive test scenarios Negative test scenarios Summary 3. Domain-Driven Design Domain-driven design fundamentals Fundamentals of DDD Ubiquitous language Multilayered architecture Presentation layer Application layer Domain layer Infrastructure layer Artifacts of domain-driven design Entities Value objects FAQs Services Aggregates Repository Factory Modules Strategic design and principles Bounded context Continuous integration Context map Shared kernel Customer-supplier Conformist Anticorruption layer Separate ways Open Host Service Distillation Sample domain service Entity implementation Repository implementation Service implementation Summary 4. Implementing a Microservice OTRS overview Developing and implementing microservices Restaurant microservice OTRS implementation Controller class API versioning Service classes Repository classes Entity classes Registration and discovery service (Eureka service) Eureka client Booking and user services Execution Testing References Summary 5. Deployment and Testing Mandatory services for good microservices Service discovery and registration Edge servers Load balancing Circuit breakers Monitoring An overview of microservice architecture using Netflix OSS Load balancing Server-side load balancing Client-side load balancing Circuit breakers and monitoring Using Hystrix's fallback methods Monitoring Setting up the Hystrix dashboard Creating Turbine services Building and running the OTRS application Microservice deployment using containers Installation and configuration Docker machine with 4 GB Building Docker images with Maven Running Docker using Maven Integration testing with Docker Pushing the image to a registry Managing Docker containers References Summary 6. Reactive Microservices An overview of the reactive microservice architecture Responsive Resilient Elastic Message driven Implementing reactive microservices Producing an event Consuming the event References Summary 7. Securing Microservices Enabling Secure Socket Layer Authentication and authorization OAuth 2.0 Usage 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 Authorization code grant Implicit grant Resource owner password credential grant Client credentials grant References Summary 8. Consuming Services Using a Microservice Web Application AngularJS framework overview MVC MVVM Modules Providers and services Scopes Controllers Filters Directives UI-Router Development of OTRS features Home page/restaurant list page index.html app.js restaurants.js restaurants.html Search restaurants Restaurant details with reservation option restaurant.html Login page login.html login.js Reservation confirmation Setting up the web application References Summary 9. Best Practices and Common Principles Overview and mindset Best practices and principles Nanoservice, size, and monolithic Continuous integration and deployment System/end-to-end test automation Self-monitoring and logging A separate data store for each microservice Transaction boundaries Microservices 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
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages372 Page
-
File Size-