Implementation of Microservices with Spring Boot on AWS and in Docker – Part 1

October 4, 2017 | Comments(0) |

Are you still bound with the platform dependent, large monolithic applications? It is time to get over the legacy applications and to taste the fruit of microservices. You are at the right place to get started with Microservices.

The times of struggling with platform dependent, large monolithic applications have become outdated. Now are the days to start with services that helps us to deploy the same application on various platforms. Here we go with uncovering the edge of Microservices with this article.

Although monolithic application is simple to build, it has huge limitations. Application grows over time and become huge. Every week or month, the development team implements few more lines of code. As time moves, application becomes huge & complicated. It is difficult for a single developer to understand the whole application. Thus, implementing new features and removing bugs is extremely difficult and time consuming. The enormous size of the application holds back the pace of development.

Latest  applications are designed in such a way that user can push changes into production multiple times in a day. It is very difficult to do the same with a complex monolithic application.

The basic idea of microservices is to breakdown an application, so that it becomes easier to build, maintain and scale.

Here are few advantages of working with microservices:

  • Microservices are small and focused on specific requirement
  • It can be developed by small teams
  • They are loosely coupled that means services are independent of each other in terms of development as well as deployment
  • Scaling microservices is very easy
  • Microservices allow many ways to integrate automatic deployments by using tools like Jenkins, Bamboo, etc.
  • It gives the advantage to use new cutting-edge technologies
  • High performance and flexible application

Now we shall go ahead & create a web application which is for compressing images. In this application, first you must register yourself with the application to upload the image for compressing. We will create three microservices: WebMicroservice, RegistrationMicroservice and S3Microservice.

The below diagram will help you to understand the flow of Microservices Application:

Microservices Application

Prerequisite

  • AWS Account with Access Key and Secret Key
  • Java 1.8
  • STS
  • WinSCP

Task 1: Create WebMicroservice

  1. Download the WebMicroservice present at
    http://files.cloudthat.com/microservices/WebMicroservice.zip
  2. Open STS and click on File, from the drop-down click on Import, as shown in image below:webmicroservices
  3. Click on General, from the dropdown. Select Existing Projects into Workspace and then click Next as shown below:existing webmicroservices projects
  4. Click on Select archive file, Select the downloaded archive file, and add this to STS and click on
  5. Open the application.properties file. Enter Server port for WebMicroservice. Enter RegistrationMicroservice url and S3UploadMicroservice url.

    Note:
    Port number for RegistrationMicroservice and S3UploadMicroservice must be on which you are going to run these services.
  6. In WebMicroservice, it contains only HTML templates and related class.
  7. Open DynamodbController.java and check the registerUser() method. In this method, we are sending the RegisterModel object to the RegisterMicroservice Microservice using RestTemplate’s postForObject Http Method.
  8. Right click on WebMicroservice project and run as a Spring Boot App. Type localhost:<port number> in web browser. Again, you can see registration page.
    When you enter all details and click on sign up button you will see the connection refused error because RegistrationMicroservice is              not running.

Task 2: Create RegistrationMicroservice

    1. Download the RegistrationMicroservice present at

    http://files.cloudthat.com/microservices/RegistrationMicroservice.zip 

  1. Import RegistrationMicroservice into STS. Follow step 2 to step 7 from Task 1.
  2. Open the application.properties Enter Access Key, Secret Key, Endpoint, Dynamodbtable name and port.

    Note: server.port
    number must be which you have given in WebMicroservice’s application.properties file’s registration.urlapplication properties
  3. Open DynamodbController.java class. You are getting the data from WebMicroservice in registeruser() method. Using @ReqestBody you will pass the data in DynamoDBModel class.Register User

Task 3: Create S3Microservice project

  1. Import S3UploadMicroservice project present at

          http://files.cloudthat.com/microservices/S3uploadMicroservice.zip

  1. Import S3UploadMicroservice into STS. Follow step 2 to step 7 from Task 1.
  2. Open the properties file. Enter Access Key, Secret Key, Endpoint, bucket name and port.

    Note: server.port
    number must be which you have given in WebMicroservice’s application.properties file’s s3.urlApplication Properties
  3. Open S3UploadMicroservice and Open S3UploadController.java. In imageUpload method you are getting the data from WebMicroservice and Implementing the logic to compress the image.
    upload webservice
  4. Right click on WebMicroservice project and run as Spring Boot App. Run RegistrationMicroservice and S3UploadMicroservice as Spring Boot App.
    spring boot app
  5. Open browser and type http://localhost:WebMicroservicePortNumaber/ then click Enter. Enter Email ID and Password for signup.
    sign up
  6. Upload any .jpg image.
    upload image
  7. Click on Download to download the compressed image.
    download image

Stay tuned to learn how to deploy these microservices in Docker Containers in my next blog article i.e. Implementation of Microservices with Spring Boot on AWS and in Docker – Part 2

Please feel free to post your views in the comment section below, I will be happy to discuss.

To know more about our training services, visit www.cloudthat.in and for consulting services, visit www.cloudthat.com


Leave a Reply