Question about how Eureka differentiates between a service provider and service consumer

553 views
Skip to first unread message

Vikash Dat

unread,
May 19, 2015, 11:40:43 AM5/19/15
to eureka_...@googlegroups.com
Based on the example code found here: https://github.com/Netflix/eureka/tree/master/eureka-examples/src/main/java/com/netflix/eureka , it seems that both the service provider and client do the same initialization and registration steps:


 
// Register with Eureka
DiscoveryManager.getInstance().initComponent(
new MyDataCenterInstanceConfig(),
new DefaultEurekaClientConfig());
ApplicationInfoManager.getInstance().setInstanceStatus(InstanceStatus.UP);
// this is the vip address for the example service to talk to as defined in conf/sample-eureka-service.properties
String vipAddress = "sampleservice.mydomain.net";
InstanceInfo nextServerInfo = null;
try {
nextServerInfo = DiscoveryManager.getInstance()
.getEurekaClient()
.getNextServerFromEureka(vipAddress, false);
} catch (Exception e) {
System.err.println("Cannot get an instance of example service to talk to from eureka");
System.exit(-1);
}

Even the service.properties and client.properties files are almost identical. The only difference I can see is that in the service.properties file, it includes a configuration for eureka.port. Does this mean that the only thing that tells the Eureka server that something is a service is if the eureka.port is in the config.file? 

Appreciate the clarification. 

dl...@netflix.com

unread,
May 19, 2015, 12:35:52 PM5/19/15
to eureka_...@googlegroups.com
Hi Vikash,

In the general case, if a server with an eureka client is configured to register with eureka servers, it is considered a service provider. Registration with the eureka servers is essentially an advertising of a server and the instanceInfo contains the contact details (ip, port etc) of the server. If a server with an eureka client is configured to read data from eureka servers, then this is a client use case.

A server with an eureka client can be both service provider and client, and the default configuration for eureka-client configures the eureka client to be both registering and reading from the eureka servers.

Thanks.

Vikash Dat

unread,
May 19, 2015, 2:01:23 PM5/19/15
to eureka_...@googlegroups.com
Thanks, but it seems the registration logic for both service provider and client are the same, at least from the sample code. Even the eureka-service.properties and eureka-client.properties file are almost identical, save for the fact that the eureka-service.properties files has the additional eureka.port config variable. We plan on utilizing some of netflix OSS in our platform, which included Eureka. I just want to make sure I understand how the registrations differ (from the sample code it is not apparent) so I can make sure that I never mistakenly register a consumer as a provider. 

Thanks

dl...@netflix.com

unread,
May 19, 2015, 3:09:12 PM5/19/15
to eureka_...@googlegroups.com
Hi Vikash,

I have updated the examples (pull https://github.com/Netflix/eureka/pull/522) to hopefully make this more clear. Would you mind taking a look and see if this answers your question? In general, the appName and vipAddress are what's used to differentiate different server(s) that provides different services.

Vikash Dat

unread,
May 19, 2015, 3:59:36 PM5/19/15
to eureka_...@googlegroups.com
+1 . Thanks for the promptness and the updated examples. They are much clearer now!
Reply all
Reply to author
Forward
0 new messages