paulc4 / microservices-demo

Demo application to go with Blog on spring.io
889 stars 830 forks source link

why account service is displaying as one in eureka console..? #8

Closed areddy7021 closed 8 years ago

areddy7021 commented 8 years ago

Hi Paul ,

It was a very nice article and everything worked as expected but i have a question related to eureka console that it is displaying only account service count as 1 instead of 2 since i am running two instances of account service in my local machine . Is there any reason behind this ?

capture

Thanks, Akhil.

paulc4 commented 8 years ago

It is one application, two instances. Eureka treats multiple instances of the same application as one application. I should probably make this clearer in the blog article.

areddy7021 commented 8 years ago

got it paul , so you are treating the one application as a context path i guess .thank you for your quick reply.

paulc4 commented 8 years ago

One of the reasons for using Eureka is to load-balance across multiple instances of the same application. The DiscoveryClient has a getNextServerFromEureka() method. Each time you call it you may get a different instance.

areddy7021 commented 8 years ago

hmm...that's really awesome but behind the scenes ..how it really maintains all these instances on eureka ..is it by any unique identifier like every instance ip address ? and what is the correct use case of using the method getNextServerFromEureka()..in a programatical way ?

TomCools commented 8 years ago

Great demo, however, i think you missed the OP point. Following your guide, when i spin up the second instance (2th account instance on port 2223) , it overwrites the application info of ACCOUNTS-SERVICE.

http://localhost:1111/eureka/apps/ always shows only 1 instance. First on port 2222. After I Launch the second instance, it's on port 2223.

What you described, that the second instances starts taking the calls, is a logical step, even if i don't kill the first instance (port 2222). If i leave the first instance (2222) on, start second instance (2223), and then i kill the second instance again after it has overwitten the config, it does not balance back to the original instance (2222) but starts throwing errors (connection refused, etc.)

What works for me: You can add meta-data to an instance, but using the eureka.instance.metadataMap.instanceId parameter. If i run:

I can see two instances: image

Balancing works correctly now, each call switches to the other instance with the default settings and killing them in any order and restoring them works.

If this was unclear, please let me know and i'll give a clearer example :-).

paulc4 commented 8 years ago

I do get what you're saying and I have been looking into this since the issue was first raised.

I now believe the instance behavior changed from the earliest versions of Spring Cloud Netflix. Originally, when running multiple instances they would automatically get unique instance names and so register as different instances.

However that has since changed and the behavior you describe is the result. You have found the correct solution, to specify a different instance id manually. If I understand things correctly, it is possible to also set that property in the bootstrap.properties file, so you don't have to do it manually.

BTW, this is only an issue if the instances run on the same host. In a "real" application they are much moire likely to be on different hosts.

I will update my blog and demo accordingly. Thanks for taking the time to look into this. I appreciate your feedback.

paulc4 commented 8 years ago

Fixed, finally. See also https://spring.io/blog/2015/07/14/microservices-with-spring#configuration-options

TomCools commented 8 years ago

Thanks :)