Book Image

Spring Microservices

By : Rajesh R V
Book Image

Spring Microservices

By: Rajesh R V

Overview of this book

The Spring Framework is an application framework and inversion of the control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions to build web applications on top of the Java EE platform. This book will help you implement the microservice architecture in Spring Framework, Spring Boot, and Spring Cloud. Written to the latest specifications of Spring, you'll be able to build modern, Internet-scale Java applications in no time. We would start off with the guidelines to implement responsive microservices at scale. We will then deep dive into Spring Boot, Spring Cloud, Docker, Mesos, and Marathon. Next you will understand how Spring Boot is used to deploy autonomous services, server-less by removing the need to have a heavy-weight application server. Later you will learn how to go further by deploying your microservices to Docker and manage it with Mesos. By the end of the book, you'll will gain more clarity on how to implement microservices using Spring Framework and use them in Internet-scale deployments through real-world examples.
Table of Contents (18 chapters)
Spring Microservices
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Microservice is an architecture style and pattern in which complex systems are decomposed into smaller services that work together to form larger business services. Microservices are services that are autonomous, self-contained, and independently deployable. In today's world, many enterprises use microservices as the default standard for building large, service-oriented enterprise applications.

The Spring framework is a popular programming framework with the developer community for many years. Spring Boot removed the need to have a heavyweight application container and provided a means to deploy lightweight, server-less applications. Spring Cloud combines many Netflix OSS components and provides an ecosystem to run and manage large-scale microservices. It provides capabilities such as load balancing, service registry, monitoring, service gateway, and so on.

However, microservices come with their own challenges, such as monitoring, managing, distributing, scaling, discovering, and so on, especially when deploying at scale. Adopting microservices without addressing the common microservices challenges would lead to catastrophic results. The most important part of this book is a technology-agnostic microservice capability model that helps address all the common microservice challenges.

The goal of this book is to enlighten readers with a pragmatic approach and guidelines for implementing responsive microservices at scale. This book will take readers on a deep dive into Spring Boot, Spring Cloud, Docker, Mesos, and Marathon. Readers of this book will understand how Spring Boot is used to deploy autonomous services server-less by removing the need to have a heavyweight application server. Readers will learn different Spring Cloud capabilities and also realize the use of Docker for containerization and of Mesos and Marathon for compute resource abstraction and cluster-wide control, respectively.

I am sure readers will enjoy each and every section of this book. Also, I honestly believe that this book adds tremendous value by successfully conceiving microservices in your business. Throughout this book, I have used practical aspects of microservices implementation by providing a number of examples, including a case study from the travel domain. In the end, you will have learned how to implement microservice architectures using the Spring framework, Spring Boot, and Spring Cloud. These are battle-tested, robust tools to develop and deploy scalable microservices. Written to the latest specifications of Spring, with the help of this book, you'll be able to build modern, Internet-scale Java applications in no time.

What this book covers

Chapter 1, Demystifying Microservices, gives you an introduction to microservices. This chapter covers the fundamental concepts of microservices, their evolution, and their relationship with service-oriented architecture, as well as the concepts of cloud native and Twelve-Factor applications.

Chapter 2, Building Microservices with Spring Boot, introduces building REST- and message-based microservices using the Spring framework and how to wrap them with Spring Boot. In addition, we will also explore some core capabilities of Spring Boot.

Chapter 3, Applying Microservices Concepts, explains the practical aspects of microservices implementation by detailing out the challenges that developers face with enterprise-grade microservices. This will also summarize the capabilities required to successfully manage a microservices ecosystem.

Chapter 4, Microservices Evolution – A Case Study, takes the readers into a real-world case study of microservices evolution by introducing BrownField Airline. Using the case study, this chapter explains how to apply the microservices concepts learned in previous chapters.

Chapter 5, Scaling Microservices with Spring Cloud, shows how to scale the previous example using Spring Cloud stack capabilities. It details out the architecture and different components of Spring Cloud and how they integrate together.

Chapter 6, Autoscaling Microservices, demonstrates the use of a simple life cycle manager to attain elasticity and the self-management of microservices by orchestrating services with service gateways. It explains how, in the real world, one can add intelligence to service gateways.

Chapter 7, Logging and Monitoring Microservices, covers the importance of logging and monitoring aspects when developing microservices. Here, we will go into the details of some of the best practices when using microservices such as centralized logging and monitoring capabilities using open source tools and how to integrate them with Spring projects.

Chapter 8, Containerizing Microservices with Docker, explains containerization concepts in the context of microservices. Using Mesos and Marathon, this chapter demonstrates a next-level implementation to replace a custom life cycle manager for large deployments.

Chapter 9, Managing Dockerized Microservices with Mesos and Marathon, explains the autoprovisioning and deployment of microservices. Here, you will also learn how to use Docker containers in the previous example for large-scale deployments.

Chapter 10, The Microservices Development Life Cycle, covers the process and practices of microservices development. The importance of DevOps and continuous delivery pipelines is also explained in this chapter.

What you need for this book

Chapter 2, Building Microservices with Spring Boot, introduces Spring Boot, which requires the following software components to test the code:

  • JDK 1.8

  • Spring Tool Suite 3.7.2 (STS)

  • Maven 3.3.1

  • Spring Framework 4.2.6.RELEASE

  • Spring Boot 1.3.5.RELEASE

  • spring-boot-cli-1.3.5.RELEASE-bin.zip

  • RabbitMQ 3.5.6

  • FakeSMTP

In Chapter 5, Scaling Microservices with Spring Cloud, you will learn about the Spring Cloud project. This requires the following software components in addition to the previously mentioned ones:

  • Spring Cloud Brixton.RELEASE

In Chapter 7, Logging and Monitoring Microservices, we will take a look at how centralized logging can be implemented for microservices. This requires the following software stack:

  • Elasticsearch 1.5.2

  • kibana-4.0.2-darwin-x64

  • Logstash 2.1.2

In Chapter 8, Containerizing Microservices with Docker, we will demonstrate how we can use Docker for microservices deployments. This requires the following software components:

  • Docker version 1.10.1

  • Docker Hub

Chapter 9, Managing Dockerized Microservices with Mesos and Marathon, uses Mesos and Marathon to deploy dockerized microservices into an autoscalable cloud. The following software components are required for this purpose:

  • Mesos version 0.27.1

  • Docker version 1.6.2

  • Marathon version 0.15.3

Who this book is for

This book is primarily for Spring developers who are looking to build cloud-ready Internet-scale applications to meet modern business demands. The book will help developers to understand what exactly microservices are and why they are important in today's world by examining a number of real-world use cases and hands-on code samples. Developers will understand how to build simple RESTful services and organically grow them to truly enterprise-grade microservices ecosystem.

This book will be interesting to architects who are seeking help on designing robust Internet-scale microservices using the Spring framework, Spring Boot, and Spring Cloud and managing them using Docker, Mesos, and Marathon. The capability model will help architects devise solutions even beyond the tools and technologies discussed in this book.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The following properties can be set in application.properties to customize application-related information."
A block of code is set as follows:

<parent>
  <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.4.RELEASE</version>
</parent>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

eureka-server2.properties
eureka.client.serviceUrl.defaultZone:http://localhost:8761/eureka/
eureka.client.registerWithEureka:false
eureka.client.fetchRegistry:false

Any command-line input or output is written as follows:

$ java -jar fakeSMTP-2.0.jar

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the Make Request button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book 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 files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Spring-Microservices. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.