EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring cloud microservices
Secondary Sidebar
Spring Tutorial
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring cloud microservices

Spring cloud microservices

Introduction to Spring Cloud Microservices

The following article provides an outline for spring cloud microservices. Microservice is an architecture that helps us to divide our application into small modules and makes it easy to manage and handle. We have a Spring cloud framework that helps us to implement this architecture in our application. It is a modern approach to develop the application in which we basically divided and separate the application code from each other and make it an independent, manageable module, etc. By the use of this, we can significantly increase productivity, easy to maintenance, greater fault tolerance etc. Furthermore, by the use of spring boot, we can make these microservices really very fast and small; we have spring cloud, which can be used with spring boot application to build this. The spring cloud has so many components that help us build the microservice quick and fast; some of them are discovery service, client registry, circuit breaker, and many more. In the coming section, we will have a closer look at the spring cloud microservice in detail for better understanding and implementation.

Syntax

In spring cloud, we have a few annotations which can make our spring boot project to act as the microservice after adding of the dependency; let have a quick look at the annotations which we are going to use later see below;

1) @EnableDiscoveryClient

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

2) @EnableEurekaServer

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)

3) etc

As you can see, we will be going to use some of the annotations from these; in the coming section, we will have a closer look at the internally working of the spring cloud microservice, which is the flow chart itself.

How does Spring cloud microservices works?

As now we already know what microservices are, now we will see how it actually works with spring cloud; in this section, we will discuss in detail wits internal working let’s get started to see below;

1) As you can see from the below flowchart, we have API gateway as the first component or layer we can say. This API gateway is responsible for performing the authentication part for all the request that is coming from the client. It acts as the entry point for our microservice. It helps us to map our request to the appropriate microservice and handle the request to them.

2) After this, we have different microservice which are deployed on the server as the independent service. Interact with the API gateway also. Once they process the request and get the response, they hand it over to the API gateway.

3) On top of these microservices, we used different components of the spring cloud framework, which helps us make our normal spring boot project as the microservice; if we do not make use of this, we cannot say it is microservice architecture.

4) We have used like, circuit breaker here for fault tolerance, config server, service registry, spring cloud sleuth and many more we can use as per the requirement.

Flowchart

Flowchart1

Working of Microservice

1) we can create the different services per our need; first, we need to identify the modules that can act as the independent module for our application.

2) after this, we can register our service to discovery service in order to make them found. Below are the main component of the spring cloud microservice;

a) Discovery service: this is the main service of spring cloud, which helps us discover our different services and let us communicate with one another. As the name suggests, it helps to discover the service. It is also known as the registered service, where all other services register themselves in order to get found by it. For this, we have to make few configurations into our application and keep in mind that it will be a separate spring boot project running on the server. We need this to keep track of our registered service, and also, it does not register itself; in the coming section, we will see the configuration required to enable this.

b) Client service: This is another form of service, but this service represents the module from our application responsible for performing some business logic and returning the result. Basically, this service provides data, or we can say actual data for the application. We can have multiple client services in our application, and this multiple services will represent the different functionality of the application. We have to register these services with the discovery service.

c) Gateway service: This service act as the entry point for our application; it can contain the common logic for our application or centralized configuration, which is needed by all the different services we have. Basically, it does the authentication part for us; we can also place our centralized logging part here; it can be anything depending on the requirement of the application.

Flowchart 2

Examples of Spring cloud microservices

Given below are the example of Spring cloud microservices:

1. Create the spring boot project from the spring initializer and add the required dependency as well. from the below URL: https://start.spring.io/

2. After this, import it to your IDE and add the below dependency for creating the eureka server,

Example:

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

3. After this, we have to add only one annotation to our main spring application class to enable the eureka server, and we can run the application to see the output:

Example:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication{
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}

4. Add the below configuration to the application file so the register will not register itself to the service, see below;

We are using a .yml file to make the configuration so that syntax will be but different for this; for reference, I am attaching the code.

Example:

server:
port: 8989
eureka:
client:
register-with-eureka: false
fetch-registry: false

5. Run the application and see the logs, as below;

Output:

Spring cloud microservices output

Conclusion

This article has seen microservice using the spring cloud framework, which makes it easy for us to build and configure. Moreover, we can easily monitor, handle, maintain it using the eureka server we have. Already we have seen the internal working as well for better understanding for beginners.

Recommended Articles

This is a guide to Spring cloud microservices. Here we discuss the working of Spring cloud microservices with a flowchart along with Examples. You may also have a look at the following articles to learn more –

  1. Spring Boot HTTPS
  2. Spring Boot Profiles
  3. Spring Boot Dependencies
  4. Spring Boot Versions
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more