What is Load Balancing in Spring Cloud and how does Spring Cloud LoadBalancer work? स्प्रिंग क्लाउड में लोड बैलेंसिंग क्या है और Spring Cloud LoadBalancer कैसे काम करता है?
When a service has multiple running instances for scalability and fault tolerance, calls to it need to be distributed across those instances rather than always hitting one. Client-side load balancing resolves the service name (from Eureka) to a specific instance address at call time, choosing among healthy instances using a strategy like round-robin.
Spring Cloud LoadBalancer is the current standard (replacing the deprecated Netflix Ribbon), integrated transparently with RestTemplate (via @LoadBalanced), WebClient, and Feign — application code calls the logical service name, and the load balancer picks and routes to a healthy instance behind the scenes.
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
restTemplate.getForObject("http://ORDER-SERVICE/api/orders/1", Order.class);जब किसी सर्विस के स्केलेबिलिटी और फॉल्ट टॉलरेंस के लिए कई चल रहे इंस्टेंस हों, तो उसकी कॉल्स को हमेशा एक ही इंस्टेंस पर भेजने के बजाय उन इंस्टेंस में वितरित करना ज़रूरी होता है। क्लाइंट-साइड लोड बैलेंसिंग कॉल के समय सर्विस नाम को (Eureka से) एक विशिष्ट इंस्टेंस एड्रेस में रिज़ॉल्व करती है।
Spring Cloud LoadBalancer वर्तमान मानक है (पुराने पड़ चुके Netflix Ribbon की जगह), जो RestTemplate, WebClient और Feign के साथ पारदर्शी रूप से इंटीग्रेट होता है — एप्लिकेशन कोड लॉजिकल सर्विस नाम को कॉल करता है, और लोड बैलेंसर पर्दे के पीछे एक स्वस्थ इंस्टेंस चुनता है।
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}Was this answer clear?