What is Service Discovery and how does Eureka work in Spring Cloud? सर्विस डिस्कवरी क्या है और स्प्रिंग क्लाउड में Eureka कैसे काम करता है?
In a microservices system, service instances scale up/down and their network locations change dynamically, so hardcoding IP addresses and ports doesn't work. Service Discovery solves this: each service registers itself with a central registry on startup, and other services query the registry to find available instances at runtime instead of using a fixed address.
Netflix Eureka, integrated via Spring Cloud Netflix, provides this registry. A Eureka Server is run as its own Spring Boot app with @EnableEurekaServer; each microservice becomes a Eureka Client with @EnableEurekaClient (or auto-detected via the client dependency), sending periodic heartbeats to stay registered, and load-balanced calls between services are resolved by service name rather than a hardcoded host.
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication { ... }
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/माइक्रोसर्विसेज़ सिस्टम में, सर्विस इंस्टेंस स्केल अप/डाउन होते हैं और उनके नेटवर्क लोकेशन गतिशील रूप से बदलते हैं, इसलिए IP एड्रेस और पोर्ट हार्डकोड करना काम नहीं करता। सर्विस डिस्कवरी इसे हल करती है: हर सर्विस स्टार्टअप पर खुद को एक केंद्रीय रजिस्ट्री में रजिस्टर करती है।
Netflix Eureka, जो Spring Cloud Netflix के ज़रिए इंटीग्रेट होता है, यह रजिस्ट्री प्रदान करता है। एक Eureka Server अपनी खुद की स्प्रिंग बूट ऐप के रूप में @EnableEurekaServer से चलाया जाता है; हर माइक्रोसर्विस Eureka Client बन जाती है, जो रजिस्टर्ड रहने के लिए समय-समय पर हार्टबीट भेजती है।
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication { ... }Was this answer clear?