Spring 5.0 Microservices - Second Edition
eBook - ePub

Spring 5.0 Microservices - Second Edition

  1. 414 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Spring 5.0 Microservices - Second Edition

About this book

A practical, comprehensive, and user-friendly approach to building microservices in SpringAbout This Book• Update existing applications to integrate reactive streams released as a part of Spring 5.0• Learn how to use Docker and Mesos to push the boundaries and build successful microservices• Upgrade the capability model to implement scalable microservicesWho This Book Is ForThis book is ideal for Spring developers who want to build cloud-ready, Internet-scale applications, and simple RESTful services to meet modern business demands.What You Will Learn• Familiarize yourself with the microservices architecture and its benefits• Find out how to avoid common challenges and pitfalls while developing microservices• Use Spring Boot and Spring Cloud to develop microservices• Handle logging and monitoring microservices• Leverage Reactive Programming in Spring 5.0 to build modern cloud native applications• Manage internet-scale microservices using Docker, Mesos, and Marathon• Gain insights into the latest inclusion of Reactive Streams in Spring and make applications more resilient and scalableIn DetailThe 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 that focuses on Reactive Programming, you'll be able to build modern, internet-scale Java applications in no time. The book starts off with guidelines to implement responsive microservices at scale. Next, you will understand how Spring Boot is used to deploy serverless autonomous services by removing the need to have a heavyweight application server.Later, you'll learn how to go further by deploying your microservices to Docker and managing them with Mesos. By the end of the book, you will have gained more clarity on the implementation of microservices using Spring Framework and will be able to use them in internet-scale deployments through real-world examples.Style and approachThe book takes a step-by-step approach on developing microservices using Spring Framework, Spring Boot, and a set of Spring Cloud components that will help you scale your applications.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Spring 5.0 Microservices - Second Edition by Rajesh R V in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

Building Microservices with Spring Boot

Developing microservices is not so tedious anymore--thanks to the powerful Spring Boot framework. Spring Boot is a framework for developing production-ready microservices in Java.
This chapter will move from the microservices theory explained in the previous chapters to hands-on practice by reviewing code samples. Here, we will introduce the Spring Boot framework, and explain how Spring Boot can help building RESTful microservices inline with the principles and characteristics discussed in the previous chapter. Finally, some of the features offered by Spring Boot for making the microservices production ready will be reviewed.
At the end of this chapter, you will have learned about the following:
  • Setting up the latest Spring development environment
  • Developing RESTful services using Spring Framework 5 and Spring Boot
  • Building reactive microservices using Spring WebFlux and Spring Messaging
  • Securing microservices using Spring Security and OAuth2
  • Implementing cross-origin microservices
  • Documenting Spring Boot microservices using Swagger
  • Spring Boot Actuator for building production-ready microservices

Setting up a development environment

To crystalize microservices' concepts, a couple of microservices will be built. For that, it is assumed that the following components are installed:
  • JDK 1.8 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
  • Spring Tool Suite 3.8.2 (STS) (https://spring.io/tools/sts/all)
  • Maven 3.3.1 (https://maven.apache.org/download.cgi)
Alternately, other IDEs like IntelliJ IDEA/NetBeans/Eclipse could be used. Similarly, alternate build tools like Gradle can be used. It is assumed that Maven repository, class path, and other path variables are set properly for running STS and Maven projects.
This chapter is based on the following versions of Spring libraries:
  • Spring Framework 5.0.0.RC1
  • Spring Boot 2.0.0. M1
The focus of this chapter is not to explore the full features of Spring Boot, but to understand some of the essential and important features of Spring Boot, required when building microservices.

Spring Boot for building RESTful microservices

Spring Boot is a utility framework from the Spring team for bootstrapping Spring-based applications and microservices quickly and easily. The framework uses an opinionated approach over configurations for decision making, thereby reducing the effort required on writing a lot of boilerplate code and configurations. Using the 80-20 principle, developers should be able to kick start a variety of Spring applications with many default values. Spring Boot further presents opportunities to the developers for customizing applications by overriding auto-configured values.
Spring Boot not only increases the speed of development, but also provides a set of production-ready ops features such as health checks and metrics collections. Since Spring Boot masks many configuration parameters and abstracts many lower level implementations, it minimizes the chances of errors to a certain extent. Spring Boot recognizes the nature of the application based on the libraries available in the classpath, and runs the auto-configuration classes packaged in those libraries.
Often, many developers mistakenly see Spring Boot as a code generator, but, in reality, it is not. Spring Boot only auto-configures build files, for example, pom files in the case of Maven. It also sets properties, such as data source properties, based on certain opinionated defaults.
Consider the following dependencies in the file pom.xml:
 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
For instance, in the preceding case, Spring Boot understands that the project is set to use the Spring Data JPA and HSQL database. It automatically configures the driver class and other connection parameters.
One of the great outcomes of Spring Boot is that it almost eliminates the need to have traditional XML configurations. Spring Boot also enables microservices development by packaging all the required runtime dependencies into a fat executable jar.

Getting started with Spring Boot

These are the different ways in which Spring Boot-based application development can be started:
  • By using Spring Boot CLI as a command-line tool
  • By using IDEs like Spring Tool Suite (STS), which provide Spring Boot, supported out of the box
  • By using the Spring Initializr project at http://start.spring.io
  • By using SDKMAN! (The Software Development Kit Manager) from http://sdkman.io
The first three options will be explored in this chapter, developing a variety of example services.

Developing a Spring Boot microservice

The easiest way to develop and demonstrate Spring Boot's capabilities is by using the Spring Boot CLI, a command-line tool.
The following are the steps to set up and run Spring Boot CLI:
  1. Install the Spring Boot command-line tool by downloading the spring-boot-cli-2.0.0.BUILD-M1-bin.zip file from the following location URL:
    https://repo.spring.io/milestone/org/springframework/boot/spring-boot-cli/2.0.0.M1/
  1. Unzip the file into a directory of choice. Open a terminal window, and change the terminal prompt to the bin folder.
Ensure that the /bin folder is added to the system path so that Spring Boot can be run from any location. Otherwise, execute from the bin folder by using the command ./spring.
  1. Verify the installation with the following command. If successful, the Spring CLI version will be printed on the console as shown:
  $spring –-version
Spring CLI v2.0.0.M1
  1. As the next step, a quick REST service will be developed in groovy, which is supported ...

Table of contents

  1. Title Page
  2. Copyright
  3. Credits
  4. About the Author
  5. Acknowledgments
  6. About the Reviewer
  7. www.PacktPub.com
  8. Customer Feedback
  9. Preface
  10. Demystifying Microservices
  11. Related Architecture Styles and Use Cases
  12. Building Microservices with Spring Boot
  13. Applying Microservices Concepts
  14. Microservices Capability Model
  15. Microservices Evolution – A Case Study
  16. Scale Microservices with Spring Cloud Components
  17. Logging and Monitoring Microservices
  18. Containerizing Microservices with Docker
  19. Scaling Dockerized Microservices with Mesos and Marathon
  20. Microservice Development Life Cycle