How do I use Eureka Service Discovery service names on Feign client? In my Feign client interface, when I add the localhost:portnumber parameter for the URL, it works correctly, but how do I use the service name from Eureka? I can use the service name when I use rest template, but I can't figure out how to do it with Feign.
I want to be able to do this so I don't hardcode URLs in case I deploy to cloud and am no longer using local host.
Comment From: spencergibb
Have you included spring-cloud-starter-netflix-eureka-client and spring-cloud-starter-netflix-ribbon?
Comment From: khan133
@spencergibb I have included Eureka Client but not ribbon. The Eureka server is registering all of the clients but I just don't know how to use the Service name with the Feign implementation.
Using rest template I was able to do this using:
UserBook listOfBooks = restTemplate.getForObject("http://book-info-service/books/getAllBooks", UserBook.class);
But for Feign interface, I have to do this to get it to work: @FeignClient(value = "Ratings-data-service", url = "http://localhost:8085/ratings") I want to change the localhost:8085 to use the service name
Comment From: spencergibb
ribbon is required. your rest-template won't work without it either.
Comment From: khan133
Rest Template worked fine for me (I'm new to Spring but I added the @Bean annotation so I'm not sure if that is why). Anyway, once I implement Ribbon and have a list of servers in the application resources file, what should I do to be able to use the service name instead of the actual url?
Comment From: spencergibb
remobe the url attribute. It uses the name attribute to find in eureka.
Comment From: khan133
Okay, thanks! Also, I am trying to get load balancing working using Ribbon and I have imported spring-cloud-starter-netflix-ribbon but when I go to application.properties, I get an error of an unknown property when I try to do server.ribbon.eureka.enabled = true (or anything related to server.ribon). I've done an update project on maven and am still getting this error
Comment From: spencergibb
that's because there isn't metadata for those properties but they should still work.
Comment From: khan133
Okay thanks. So, when I do server.ribbon.listofservers:
What should I put there if I want to use the service name from eureka?
Comment From: spencergibb
you shouldn't need to do that if using eureka and ribbon.
Comment From: khan133
It all works correctly now, thank you so much!