A simple microservice example

We will discuss a simple microservice example with Spring Boot and Cloud. In a previous chapter, we saw an example of the Bank application with three microservices—AccountService, CustomerService, and Notification Service.

Without the microservice architecture, let's see the following diagram of the monolith application with these three modules:

In the preceding diagram, you can see that Banking Application has three modules—AccountService, CustomerService, and Notification Service. AccountService manages the account of the customer in the banking system, such open account, get details of an account, update details of an account, and close an account.

Let's divide this monolithic banking application into separate pieces according to the AccountService, CustomerService, and NotificationService modules. These modules process independently of each other. We can deploy each service separately without hampering other services. Its scope is microscopic and focuses only on a unit of task rather than too many tasks. Let's see the following diagram of this banking application based on the microservice architecture:

As you can see in the preceding diagram, we created the banking application with a microservices-based architecture. The banking application has been divided into a set of sub-applications, called microservices.

I am going to discuss how to implement a large system by building the simplest possible subsystems step-by-step. Therefore, I will only implement a small part of the big system—the user account service. I will discuss only one module of this large banking application. Let's see the following diagram of one of modules of the application:

I am going to create an AccountService microservice for one of the modules of the Banking application. The web application makes a request to access data from AccountService using the RESTful API. We need to add a discovery service, so that other processes can find each other.

Finally, we will create an account resource exposing several RESTful services using the proper URIs and HTTP methods, as follows:

  • Retrieve all accounts: @GetMapping("/account")
  • Get details of a specific account: @GetMapping("/account/{accountId}")
  • Delete an account: @DeleteMapping("/account/{accountId}")
  • Create a new account: @PostMapping("/account")
  • Update account details: @PutMapping("/account/{accountId}")

As you can see, the preceding URIs provide all the CRUD operations for the account microservice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.63.95