<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vinay Sarode on Medium]]></title>
        <description><![CDATA[Stories by Vinay Sarode on Medium]]></description>
        <link>https://medium.com/@vinay.sarode?source=rss-cf9f96d3fe2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*H69zJqWJ9iZgHdwL</url>
            <title>Stories by Vinay Sarode on Medium</title>
            <link>https://medium.com/@vinay.sarode?source=rss-cf9f96d3fe2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:53:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vinay.sarode/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Spring Cloud Netflix]]></title>
            <link>https://medium.com/globant/spring-cloud-netflix-d7db3b3c13e6?source=rss-cf9f96d3fe2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7db3b3c13e6</guid>
            <category><![CDATA[service-registry]]></category>
            <category><![CDATA[eureka]]></category>
            <category><![CDATA[spring-cloud-netflix]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vinay Sarode]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 05:33:09 GMT</pubDate>
            <atom:updated>2022-06-27T13:50:50.685Z</atom:updated>
            <content:encoded><![CDATA[<p>Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations, you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka).</p><h3>What is Service Discovery?</h3><p>A distributed system typically comprises a large number of services which communicate with each other to perform certain operations. Service discovery is the process of one service dynamically discovering the network location (IP address and port) of another service to communicate with it.</p><p>Imagine a scenario in which one REST service (Service A) is trying to invoke another REST service (Service B). In order to make a request, Service A needs to know the network location (IP address and port) of Service B. In a conventional SOA (Service Oriented Architecture) ecosystem, services’ network locations would hardly change, as they are deployed in on-premise data centers. Consequently, you can afford to maintain the network locations of services in configuration files, which will be updated infrequently. For example, Service A can maintain the IP address and port of Service B in a configuration file and use those values when making a request. Following figure illustrates this flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*NSKU3ZVG5tA8dDjw4HdNqw.png" /></figure><p>However, this approach is nearly impossible in a cloud based microservice architecture due to following reasons.</p><p><strong>Increased number of services: </strong>As you may well aware, microservice architecture is all about breaking down monoliths into fine grained services. This results in an increased number of services that forms a complex communication mesh. Therefore, it is difficult for one service to maintain the network locations of all the other services, that it has to communicate with, in a property file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*Awv04wQKOfLUzhLp6222Jg.png" /></figure><p><strong>Dynamically assigned network locations: </strong>Microservices are generally deployed in the cloud. Server instances in cloud have dynamically assigned network locations. In addition, due to its basic features such as auto scaling, servers just come and go in cloud. Each time a service is started in a new instance, its network location changes. Therefore, it is hard to maintain the target IP addresses and port numbers of a particular microservice in a property file, as the values tend to change quite frequently.</p><p>These complications raised the need to have a more sophisticated mechanism for microservices to dynamically discover the network locations of other microservices for communication. The concept of service discovery was introduced as a result. Service discovery mechanism uses a central registry to maintain the network locations of all the microservices. If for some reason the IP address and the port number of a particular microservice changes, new values will be immediately re-registered in the registry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UD6JAKZxutxGmuAsxDVbHA.png" /></figure><h3>What is Spring Cloud Eureka</h3><p>Eureka is a REST based service which is primarily used for acquiring information about services that you would want to communicate with. This REST service is also known as <strong>Eureka Server</strong>. The Services that register in Eureka Server to obtain information about each other are called <strong>Eureka Clients</strong>. Following diagram illustrates how Eureka clients and server fit in together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*fBnYsXeuaSHQ53auwsFauQ.png" /></figure><h3>Features</h3><p>Spring Cloud Netflix features:</p><ul><li>Eureka instances can be registered and clients can discover the instances using Spring-managed beans.</li></ul><p><strong>Netflix Eureka</strong><br>Eureka mainly consists of main components, let’s see what they are:<br><strong>1. Eureka Server: </strong>It is an application that contains information about all client service applications. Each microservice is registered with the Eureka server and Eureka knows all the client applications running on each port and IP address. Eureka Server is also known as Discovery Server.<br><strong>2. Eureka Client: </strong>It’s the actual microservice and it registers with the Eureka Server, so if any other microservice wants the Eureka Client’s address then they’ll contact the Eureka Server. All operations with Eureka Clients may take some time to be reflected on Eureka Server, and then on other Eureka Clients</p><p><strong>Eureka Server</strong></p><p>Implementing a Eureka Server for service registry is as below:</p><ol><li>adding spring-cloud-starter-netflix-eureka-server to the dependencies</li><li>enabling the Eureka Server in a @SpringBootApplication by annotating it with @EnableEurekaServer</li><li>configuring some properties</li></ol><p>Let’s do it step by step.</p><p>First, we’ll create a new Maven project and put the dependencies in it. Notice that we’re importing the spring-cloud-starter-parent to all the projects described in this tutorial.</p><pre>&lt;dependencies&gt;<br> &lt;dependency&gt;     <br>  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;     <br>  &lt;artifactId&gt;spring-cloud-starter-netflix-eureka-  server&lt;/artifactId&gt; <br> &lt;/dependency&gt;  </pre><pre>&lt;dependencies&gt;<br>&lt;dependencyManagement&gt;     <br> &lt;dependencies&gt;         <br>&lt;dependency&gt;             &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;             &lt;artifactId&gt;spring-cloud-starter-parent&lt;/artifactId&gt;             &lt;version&gt;Greenwich.RELEASE&lt;/version&gt;             <br>&lt;type&gt;pom&lt;/type&gt;             <br>&lt;scope&gt;import&lt;/scope&gt;         <br>&lt;/dependency&gt;     <br>&lt;/dependencies&gt;  <br>&lt;/dependencyManagement&gt;</pre><p>Then we’ll create the main application class:</p><pre>@SpringBootApplication <br>@EnableEurekaServer <br>public class <strong>EurekaServerApplication</strong> <br>{     <br>  public static void main(String[] args) {         SpringApplication.run(EurekaServerApplication.class, args);     <br>  } <br>}</pre><p>Finally, we’ll configure the properties in <em>YAML</em> format, so an <em>application.yml</em> will be our configuration file:</p><pre>server:   <br> port: 8761 <br>eureka:   <br> client:     <br>  registerWithEureka: false     <br>  fetchRegistry: false</pre><p><strong>Here we’re configuring an application port; the default one for <em>Eureka </em>servers is <em>8761</em>.</strong> We’re telling the built-in <em>Eureka Client</em> not to register with itself because our application should be acting as a server.</p><p>Now we’ll point our browser to <a href="http://localhost:8761/">http://localhost:8761</a> to view the <em>Eureka</em> dashboard, where we’ll later inspect the registered instances.</p><p><strong>Eureka Client</strong></p><p>For a <em>@SpringBootApplication</em> to be discovery-aware, we have to include a <em>Spring Discovery Client </em>(for example, <a href="https://search.maven.org/search?q=spring-cloud-starter-netflix-eureka-client"><em>spring-cloud-starter-netflix-eureka-client</em></a>) into our <em>classpath.</em></p><p>Then we need to annotate a <em>@Configuration</em> with either <em>@EnableDiscoveryClient </em>or<em> @EnableEurekaClient. </em>Note that this annotation is optional if we have the <em>spring-cloud-starter-netflix-eureka-client</em> dependency on the classpath.</p><p>The latter tells <em>Spring Boot</em> to use Spring Netflix Eureka for service discovery explicitly. To fill our client application with some sample-life, we’ll also include the <a href="https://search.maven.org/classic/#search%7Cgav%7C1%7Cg%3A%22org.springframework.boot%22%20AND%20a%3A%22spring-boot-starter-web%22"><em>spring-boot-starter-web</em></a> package in the <em>pom.xml</em> and implement a <em>REST</em> controller.</p><p>But first, we’ll add the dependencies. Again, we can leave it to the <em>spring-cloud-starter-parent </em>dependency to figure out the artifact versions for us:</p><pre>&lt;dependency&gt;     <br>&lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;     <br>&lt;artifactId&gt;spring-cloud-starter-netflix-eureka-starter&lt;/artifactId&gt; &lt;/dependency&gt; <br>&lt;dependency&gt;     <br>&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;     <br>&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; <br>&lt;/dependency&gt;</pre><p>Here we’ll implement the main application class:</p><pre>@SpringBootApplication <br>@RestController <br>public class <strong>EurekaClientApplication</strong>{      <br>@Autowired     <br>@Lazy     <br>private EurekaClient eurekaClient;      @Value(&quot;${spring.application.name}&quot;)     <br>private String appName;      <br>public static void <strong>main</strong>(String[] args) {          SpringApplication.run(EurekaClientApplication.class, args);     }      @Override     <br>public String <strong>greeting</strong>() {         <br>return String.format(&quot;Hello from &#39;%s&#39;!&quot;, eurekaClient.getApplication(appName).getName());<br>} }<br></pre><h3>Conclusion</h3><p>The prime objective of this piece was to give you an introduction to using Eureka for service discovery. In a real-world scenario, a microservice ecosystem could have thousands of services deployed in different regions of the world. In that case, it may not be practical to have just one Eureka cluster. Instead, we will have to deploy multiple Eureka clusters in different regions to minimize the latency and increase availability. This is illustrated in the below figure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7db3b3c13e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/globant/spring-cloud-netflix-d7db3b3c13e6">Spring Cloud Netflix</a> was originally published in <a href="https://medium.com/globant">Globant</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>