Microservices with Spring Cloud and Spring Boot

Microservices with Spring Cloud – VERSION 1

This is a microservices application with Spring Cloud version 1 using Spring Boot

Microservices using Spring Boot and Spring Cloud

Local Git Repository

Let’s quickly see the components and libraries that Spring Cloud uses in its version 1. Once the code is downloaded and all the microservices are launched, it should be easy to identify all the components and see how they work.

Feign REST Client for Service Invocation

Feign makes it very easy to invoke other microservices, other RESTful services. The other additional thing that Feign provides is it provides integration with something called Ribbon.

Ribbon is a client-side load balancing framework.

  • Maven dependency 

  • Scan package

  • Create proxy

  • Invoke other microservice

  • Browser call

Setting up client side load balancig with Ribbon

In the production environment we are going to have one instance of CurrencyCalculationService and three instances of CurrencyExchange Service.

  • Maven dependency 

  • Enable Ribbon in the proxy
@RibbonClient(name="currency-exchange-service")
  • Several instances to check:

You can run multiple instances of the microservice to check that load balancing is working properly.

  • Eureka naming server:

Direct call to each instance:
# http://localhost:8000/currency-exchange/from/USD/to/INR
# http://localhost:8001/currency-exchange/from/USD/to/INR
# http://localhost:8002/currency-exchange/from/USD/to/INR

Through the gateway:

# Zuul API GATEWAY
# http://localhost:8765/currency-exchange-service/currency-exchange/from/USD/to/INR

Reload the browser continuously and in the response you will see that the port number changes, the different instances respond. The load balancer works.

Call from the other microservice:

# http://localhost:8100/currency-conversion-feign/from/USD/to/INR/quantity/90

# http://localhost:8100/currency-conversion/from/USD/to/INR/quantity/90

Through the gateway:

# Zuul API GATEWAY
# http://localhost:8765/currency-conversion-service/currency-conversion-feign/from/USD/to/INR/quantity/10

Reload the browser continuously and in the response you will see that the port number changes, the different instances respond. The load balancer works.

Naming server

# http://localhost:8761/

Zuul Api Gateways

  • Authentication, authorization and security
  • Rate Limits
  • Fault Toleration
  • Service Aggregation

In this case we will intercept the calls to set a logging filter.

Distributed Tracing: Spring Cloud Sleuth with Zipkin

Right bow we have several microservices, one API gateway, naming server and configuration server.

If we want to solve a problem and if we want to debug a problem through this we would need a centralized kind of information.

We are going to use Spring Cloud Sleuth with Zipkin.

Spring Cloud Sleuth would assign a unique ID to a request so that we can trace it across.

We add the Sleuth dependency to the microservices and API gateway.

If we establish a log in the endpoints we will see the identifier of each request.

Components Zipkin is a distributed tracing system.

What we would do is all the log from all these services we would put it in MQ we would use rabbitMQ. We would send it out to the Zipkin server where it is consolidated. And we would be able to look through the different requests and find what happened with the specific request.

Install Rabbit MQ

Install Zipkin

Connecting microservice to Zipkin

Zipkin UI Dashboard:

Spring Cloud Bus

It allows us to have all the instances of the microservice updated with the changes that occur in the configuration git repository. We will make use of the RabbitMQ server.

Fault Tolerance with Hystrix

If there are problems in a microservice, we ensure that the dependent microservices continue to be available and do not go down.

In the next post we will see the changes that have occurred in version 2 of Spring Cloud. The use of docker compose will greatly facilitate our work, avoiding long and tedious installation processes such as those described in the documentation of Zipkin and Rabbit MQ.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *