0% found this document useful (0 votes)
32 views2 pages

SpringBoot7AM 01022021

This document discusses intra-communication between microservices using Spring Cloud clients. It explains that intra-communication is used for data exchange between microservices. The three Spring Cloud clients that can be used are DiscoveryClient, LoadBalancerClient, and FeignClient. DiscoveryClient is used to fetch service instance details like host and port from Eureka. It provides a list of service instances by service ID. The full flow of communication using DiscoveryClient involves registering microservices with Eureka, making a request to the consumer microservice, using DiscoveryClient to get producer service instance details from Eureka, creating a URL using the service instance, and making an HTTP request using RestTemplate.

Uploaded by

Sambit baral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

SpringBoot7AM 01022021

This document discusses intra-communication between microservices using Spring Cloud clients. It explains that intra-communication is used for data exchange between microservices. The three Spring Cloud clients that can be used are DiscoveryClient, LoadBalancerClient, and FeignClient. DiscoveryClient is used to fetch service instance details like host and port from Eureka. It provides a list of service instances by service ID. The full flow of communication using DiscoveryClient involves registering microservices with Eureka, making a request to the consumer microservice, using DiscoveryClient to get producer service instance details from Eureka, creating a URL using the service instance, and making an HTTP request using RestTemplate.

Uploaded by

Sambit baral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Date : 01/02/2021

Spring Boot 7AM


Mr. RAGHU
----------------------------------------------
Spring Cloud : Intra Communication

=> 1 Application (1 Project) => n Services (n Modules)


=> 1 Service ( 1 Module ) -> 1 Microservice(Project)

Intra Communication: 1 Microservice --- 1 Microservice


same concept in Monolithic App is called as Modules Integration.

=> Intra Communication is for data exchange. This can be implemented


using Spring Cloud clients(3):

a) DiscoveryClient
b) LoadBalancerClient
c)*** FeignClient

a) DiscoveryClient:This client is used to fetch MS details from Eureka


as List<ServiceInstance> by using ServiceId.
Once we get ServiceInstance(SID,IID,HOST,PORT,LOAD) create one
URL and make one request using RestTemplate.

** DO NOT HARDCODE IP/PORT DETAILS, THOSE MAY GET MODIFIED.


=> If we use RestTemplate only, we should hardcode URL of other MS
even that will not support LoadBalance.
-Ex:-
String url="http://192.168.0.1:9900/show";
RestTemplate rt = new RestTemplate();
rt.getForEntity(url,___);

----------------------------------------------------------------
Project ( Dep, Employee ) --> Microservices
DeptMs
EmployeeMs

1...*
Dep -------<> Employee
=> This is called as Module Integration in Monolithic.
In MS, this is called as Intra Communication.

---------------------Discovery Client Full flow----------------


*) Define Two MicroserviceApps and Register with Eureka Server.
(You can run MS in any servers/System/IP)
-> All MS details are stored in Eureka as ServiceInstance
[SID,IID,IP/HOST,PORT,LOAD].

#1. Request is made by end client/API Gateway to Consumer MS.


#2. RestController is executed based on Path/Method Type.
#3. This MS(Consumer), wants to Communicate with Another MS (Producer)
So, using DiscoveryClient that gets details of Producer MS.

#4. DiscoveryClient makes call to Eureka (FIND) by using ServiceId


of Producer.

#5.*** Consider now Eureka has single instance of Producer.


(or it may have Multiple Instance of producer), Result is
List<ServiceInstance> returned back to Consumer.
#6. Create URL (URI + Path, Get URI from ServiceInstance).
and use RestTemplate to make HTTP call.

Here,
URL = Protocol :// IP : PORT / Path / Path
URI = Protocol :// IP : PORT

URL = http://192.168.0.3:9898/employee/find
URI = http://192.168.0.3:9898

#7. Now RestTemplate, makes HTTP Request to Producer App.


#8. Producer process the request and returns some data
ResponseEntity<T>

#9. Response is returned back to Consumer RestTemplate.


#10. RestTemplate reads data and may do processing.
#11 Return back to RestController(Consumer).
#12. Final Response is given back to end client/API Gateway.

You might also like