0% found this document useful (0 votes)
81 views

SpringBoot7AM 03022021

Here are the meanings of those terms: RELEASE - A release version of a software product that is made available to customers. It has passed testing and is considered stable and ready for general use. GA - Stands for "General Availability". Indicates a release version that is considered final and is the primary focus for mainstream customer adoption and sales. Milestone - A significant point in the development of a project. Milestones mark the completion of a development phase and allow testing before moving to the next phase. They help track progress. SNAPSHOT - An interim version of a software project under development. Snapshots are built continuously from the latest codebase and are intended for testing purposes only. They may be unstable as development

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)
81 views

SpringBoot7AM 03022021

Here are the meanings of those terms: RELEASE - A release version of a software product that is made available to customers. It has passed testing and is considered stable and ready for general use. GA - Stands for "General Availability". Indicates a release version that is considered final and is the primary focus for mainstream customer adoption and sales. Milestone - A significant point in the development of a project. Milestones mark the completion of a development phase and allow testing before moving to the next phase. They help track progress. SNAPSHOT - An interim version of a software project under development. Snapshots are built continuously from the latest codebase and are intended for testing purposes only. They may be unstable as development

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/ 4

Date : 03/02/2021

Spring Boot 7AM


Mr. RAGHU
------------------------------------
Code Link:
https://www.mediafire.com/file/t7dvehxov49evsk/
SpringCloudLoadBalacerClient_03022021_RAGHU_7AM.zip/file

Microservices: Intra Communication

*) Limitations in Discovery Client:-


a) It is fetching all Services Instances as a List.
Actually only one ServiceInstance is required.

b) We need to choose one SI manually.


But it must be selected based on Load Factor.

*) ie Client Should Fecth only one SI instance


which has less load factor.

-------------------------------------------------------------
LoadBalancerClient (LBC)

*) This client is used to fetch one ServiceInstance from Eureka


which has less Load Factor.

*) If multiple Instances are having same load then random


ServiceInstance is selected.

*) Here, LoadBalancerClient is a interface. It has one abstract method


choose(ServiceId) that takes ServiceId of Producer App. It gets
only one ServiceInstance object.

*) By using SI (ServiceInstance), read URI -> add Path (URL)->


Make HTTP Request.

*) Spring Cloud Netflix has provided Ribbon, that provides Impl for
LoadBalancerClient(I) which must be used at consumer side.
[Client Side Load Balancer]

*** Server Side Load Balance: Running Producer App multiple times
[Horizontal Scaling]

=> We need to add InstanceId. If there is only One Instance, then


SID is taken as IID[Event not required to provide manually].
But if we have multiple Instances, must give any ID(number)

Provide as:
eureka.instance.instance-id=${spring.application.name}:${random.value}

Client Side Load Balance : Feching one Instance from Register


that has less load factor at Consumer side.

=> Add Ribbon Dependency that gives Impls to LoadBalancerClient(I)


named as : RibbonLoadBalancerClient(C), that comes with
auto-configuration.
-------------------------Example Application-------------------
1. Eureka Server
Name : SpringCloudLBCEureka
Dep : Eureka Server

> At starter class : @EnableEurekaServer

--application.properties--
server.port=8761
eureka.client.fetch-registry=false
eureka.client.register-with-eureka=false
--------------------------------------------------------------

2. Producer Application
Name : SpringCloudLBCBranchService
Dep : Eureka Discovery Client, Web

> AT Starter: @EnableEurekaClient

---application.properties---
server.port=9904
spring.application.name=BRANCH-SERVICE
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
eureka.instance.instance-id=${spring.application.name}:${random.value}

#eureka.client.fetch-registry=true
#eureka.client.register-with-eureka=true
-----------------------------------

> RestController
package in.nareshit.raghu.rest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/branch")
public class BranchRestController {

@Value("${server.port}")
private String port;

@GetMapping("/info")
public ResponseEntity<String> getData() {
return ResponseEntity.ok("FROM BRANCH SERVICE => " + port);
}
}

------------------------------------------------------
3. Consumer Application
Name : SpringCloudLBCCompanyService
Dep : Eureka Discovery Client, Web, Ribbon

=> At Starter: @EnableEurekaClient


--application.properties--
server.port=8686
spring.application.name=COMPANY-SERVICE
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
--------------------------

*) RestConsumer
package in.nareshit.raghu.consumer;

import java.net.URI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class BranchRestConsumer {

//Autowire Load balancer Client


@Autowired
private LoadBalancerClient client;

public String getBranchInfo() {


//get SI details from Eureka using ServiceId
ServiceInstance si = client.choose("BRANCH-SERVICE");

// read URI and add Path


URI uri = si.getUri();
String url = uri + "/branch/info";

//Make HTTP call


RestTemplate rt = new RestTemplate();
ResponseEntity<String> resp = rt.getForEntity(url, String.class);

//return response body


return resp.getBody();
}

*) RestController
package in.nareshit.raghu.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import in.nareshit.raghu.consumer.BranchRestConsumer;

@RestController
@RequestMapping("/company")
public class CompanyRestController {
@Autowired
private BranchRestConsumer consumer;

@GetMapping("/details")
public ResponseEntity<String> viewMsg() {
String body ="FROM COMPANY =>" + consumer.getBranchInfo();
return ResponseEntity.ok(body);
}
}
--------------Execution----------------------
1) Run Eureka Server (one time)
2) Run Producer (BranchService) 3 times by chaning PORT number
3) Run Consumer (CompanyService ) 1 time
4) Goto Eureka Server and check all instances
5) Click on (Company) Consumer link and convert Full URL
http://192.168.0.8:8686/actuator/info

http://192.168.0.8:8686/company/details
6) Refresh to see LoadBalancer output.

---------------------------------------------------
Q) What are meaning for below words?
RELEASE, GA, MileStone, SNAPSHOT

You might also like