{"id":3435,"date":"2025-12-24T10:01:21","date_gmt":"2025-12-24T15:01:21","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3435"},"modified":"2025-12-24T10:01:21","modified_gmt":"2025-12-24T15:01:21","slug":"service-discovery-with-spring-cloud-discovery-eureka","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/service-discovery-with-spring-cloud-discovery-eureka\/","title":{"rendered":"Service Discovery with Spring Cloud Discovery Eureka"},"content":{"rendered":"\n<p>Spring Cloud Discovery Eureka is a service registry that enables applications to dynamically discover other applications in a microservice architecture. With Eureka, applications can register themselves with the registry and then retrieve information about other registered applications. This information can be used to load balance requests across multiple instances of a service or to find the location of a specific instance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting Instances of All Services<\/h3>\n\n\n\n<p>To retrieve a list of all instances registered with the Eureka server, you can use the <code>getServices()<\/code> method of the <code>DiscoveryClient<\/code> interface. For example, the following code snippet retrieves a list of all registered services:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;String, List&lt;ServiceInstance&gt;&gt; services = discoveryClient.getServices();<br><\/code><\/pre>\n\n\n\n<p>This code will return a map where the keys are the service names and the values are lists of <code>ServiceInstance<\/code> objects. You can iterate over this map to access the information about each service and its instances.<\/p>\n\n\n\n<p>Here&#8217;s an example of how to print the name of each service and the number of instances:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (Map.Entry&lt;String, List&lt;ServiceInstance&gt;&gt; entry : services.entrySet()) {\n  String serviceName = entry.getKey();\n  int instanceCount = entry.getValue().size();\n  System.out.println(\"Service: \" + serviceName + \", Instances: \" + instanceCount);\n}\n<\/code><\/pre>\n\n\n\n<p>This code will print a list of service names and the number of instances for each service registered with the Eureka server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Getting Specific Instances<\/h3>\n\n\n\n<p>To retrieve a list of instances for a specific service name, you can use the <code>getInstances()<\/code> method of the <code>DiscoveryClient<\/code> interface. For example, the following code snippet retrieves a list of instances for the service named &#8220;user-service&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;ServiceInstance&gt; instances = discoveryClient.getInstances(\"user-service\");\n<\/code><\/pre>\n\n\n\n<p>This code will return a list of <code>ServiceInstance<\/code> objects, each of which contains information about an instance of the specified service, such as its host, port, and status. You can iterate over this list to access the information about each instance.<\/p>\n\n\n\n<p>Here&#8217;s an example of how to print the host and port of each instance to the console:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (ServiceInstance instance : instances) {\n  System.out.println(\"Instance: \" + instance.getHost() + \":\" + instance.getPort());\n}\n<\/code><\/pre>\n\n\n\n<p>This code will print a list of host and port pairs for each instance of the &#8220;user-service&#8221;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using Instances to Communicate with Services<\/h3>\n\n\n\n<p>Once you have a list of instances for a service, you can use their host and port information to communicate with them directly. For example, if you want to call a REST API endpoint on an instance of the &#8220;user-service&#8221;, you could use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String url = \"http:\/\/\" + instance.getHost() + \":\" + instance.getPort() + \"\/api\/users\";\nRestTemplate restTemplate = new RestTemplate();\nResponseEntity&lt;User&gt; response = restTemplate.getForEntity(url, User.class);\n<\/code><\/pre>\n\n\n\n<p>This code will make a GET request to the specified URL and deserialize the response into a <code>User<\/code> object.<\/p>\n\n\n\n<p>Spring Cloud Discovery Eureka makes it easy to discover and communicate with services in a microservice architecture. By using the <code>DiscoveryClient<\/code> interface, applications can easily retrieve information about registered services and instances, enabling dynamic load balancing and communication between services.<\/p>\n\n\n\n<p>Sure, here&#8217;s an updated version of the article that includes examples of getting instances of all services and specific instances:<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Cloud Discovery Eureka is a service registry that enables applications to dynamically discover other applications in a microservice architecture. With Eureka, applications can register themselves with the registry and then retrieve information about other registered applications. This information can be used to load balance requests across multiple instances of a service or to find [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3436,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[432],"tags":[319],"series":[397],"class_list":["post-3435","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring_discovery","tag-spring","series-spring"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/compass-5261062_640.jpg?fit=640%2C427&ssl=1","jetpack-related-posts":[{"id":3818,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/navigating-the-microservice-maze-using-the-discovery-client-for-service-instance-identification\/","url_meta":{"origin":3435,"position":0},"title":"Navigating the Microservice Maze: Using the Discovery Client for Service Instance Identification","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In the world of microservices, applications are broken down into smaller, independent services that communicate with each other over a network. This distributed architecture offers numerous benefits like scalability, resilience, and independent deployments. However, it also introduces the challenge of service discovery \u2013 how do services locate and communicate with\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/ai-generated-7945684_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/ai-generated-7945684_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/ai-generated-7945684_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/ai-generated-7945684_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/ai-generated-7945684_1280.avif 3x"},"classes":[]},{"id":3721,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/load-balancing-in-spring-gateway-discovery\/","url_meta":{"origin":3435,"position":1},"title":"Load Balancing in Spring: Gateway &amp; Discovery","author":"Jeffery Miller","date":"December 17, 2025","format":false,"excerpt":"Load balancing is crucial in modern applications to distribute traffic across multiple instances of a service, ensuring high availability and fault tolerance. Spring provides robust mechanisms for load balancing, both at the gateway level and through service discovery. This blog post will explore both approaches, highlighting their differences and use\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/network-8198745_1280-jpg.avif 3x"},"classes":[]},{"id":3828,"url":"https:\/\/www.mymiller.name\/wordpress\/spring-gateway\/load-balancing-your-microservices-configuring-spring-cloud-gateway-with-spring-discovery-server\/","url_meta":{"origin":3435,"position":2},"title":"Load Balancing Your Microservices: Configuring Spring Cloud Gateway with Spring Discovery Server","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"In a microservices architecture, ensuring high availability and distributing traffic evenly across multiple instances of a service is paramount. Spring Cloud Gateway, when integrated with a Spring Discovery Server (like Netflix Eureka, Consul, or Spring Cloud Service Registry), provides a powerful and straightforward way to achieve client-side load balancing without\u2026","rel":"","context":"In &quot;Spring Gateway&quot;","block_context":{"text":"Spring Gateway","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring-gateway\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2025\/04\/meditation-3814069_1280.avif 3x"},"classes":[]},{"id":3444,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-boot-admin-server-with-spring-cloud-discovery\/","url_meta":{"origin":3435,"position":3},"title":"Spring Boot Admin Server with Spring Cloud Discovery","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Boot Admin Server is a powerful tool for monitoring and managing Spring Boot applications. It provides a centralized dashboard for viewing application health, metrics, and logs. Spring Cloud Discovery, on the other hand, enables service registration and discovery for microservices-based applications. By integrating Spring Boot Admin Server with Spring\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3441,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-cloud-gateway-with-spring-cloud-discovery\/","url_meta":{"origin":3435,"position":4},"title":"Spring Cloud Gateway with Spring Cloud Discovery","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Cloud Gateway and Spring Cloud Discovery are powerful tools for building microservices architectures. Spring Cloud Gateway acts as an API gateway, routing requests to the appropriate microservices. Spring Cloud Discovery provides a registry for microservices, enabling dynamic service discovery and load balancing. In this comprehensive guide, we'll delve into\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/trees-2900064_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/trees-2900064_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/trees-2900064_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3701,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/simplifying-microservices-communication-with-the-java-spring-discovery-client\/","url_meta":{"origin":3435,"position":5},"title":"Simplifying Microservices Communication with the Java Spring Discovery Client","author":"Jeffery Miller","date":"April 20, 2026","format":false,"excerpt":"In the world of microservices, services need to find and communicate with each other dynamically. This is where the Java Spring Discovery Client comes in, offering a streamlined way to interact with a service registry (like Eureka, Consul, or Zookeeper). Let\u2019s explore its core APIs and illustrate their usage with\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/compass-4713642_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/compass-4713642_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/compass-4713642_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/compass-4713642_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/09\/compass-4713642_1280-jpg.avif 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3435"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3435\/revisions"}],"predecessor-version":[{"id":3437,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3435\/revisions\/3437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3436"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3435"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}