How can I get the Discovery Client working when using spring-cloud together with netflix Eureka?

nesohc

I'm trying to make a basic project using spring cloud with the netflix addons such as Hystrix, Eureka and Ribbon to learn how this works. The project I'm trying to make is a simple message server that will keep messages. And a message-client that will just ask the server for a message, and I want to use the auto discovery client for this, or the RestTemplate discovery. But I can't get either to work.

I have the following structure:

  • message-client (eureka client)
  • message-server (eureka client)
  • configuration-service (config server)
  • discovery-service (eureka server)

What I currently do is I start up the configuration-service, and expose the application.yml details to all of these "apps/clients" when they are connecting by the following structure:

  • config-service\src\main\resources\config\appname.yml
  • app\src\main\resources\bootstrap.yml (contains the appname and url to cloud config)

This is working just fine, and my apps start up on the port they receive from the config server, as well as they all connect to my eureka server, and all of them are visible there. As well as the Hystrix failover is also working, not that it is related to this but it tells me that it can't be completely wrong then.

But here comes my confusion... When using the @Autowired annotation in my service class (@Service annotated) inside my client module, I get a discoveryClient object, but I am unable to find any other services using that one.

Message Client - boot class:

@EnableAutoConfiguration
@EnableHystrix
@EnableEurekaClient
@ComponentScan("cloud.rest.resources, spring.cloud.client")
public class ClientBoot {
    public static void main(String[] args) {
        SpringApplication.run(ClientBoot.class, args);
    }
}

Message Client - REST Resource:

@RestController
public class MessageResource {
    @Autowired
    private MessageClient messageClient;
    @RequestMapping(value = "/message/{client}", method = RequestMethod.GET)
    public Message getMessage(@PathVariable String client) {
        return messageClient.getMessage(client);
    }
}

Message Client - MessageClient:

@Service
public class RestMessageClient implements MessageClient {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private RestTemplate restTemplate;
    @Override
    public Message getMessage(String client) {
        return restTemplate.getForObject(String.format("http://message-server/message/%s", client), Message.class);
    }
}

My message server boot class that is holding the messages has the same annotations as my client one.

And as I said, my service class are unable to find anything.. Which leads me to all of my questions:

  1. What is required to actually use ribbon load balancer?
  2. Do I have to use ribbon to be able to use the "auto discovery", I thought not but now I'm just confused.
  3. From what I've understood, when using EnableEurekaClient I should not need to use the EnableDiscoveryClient as well?
  4. Can I change the yml files on my config-server for the clients in runtime and just have to reboot the client?
  5. How much configuration is really meant to be shared by the config-server, because currently all of my clients just contain a super basic bootstrap.yml file.
  6. Does anyone have a good link to where I can read more about all the properties that is being set in my yml files? Both a documentation of what the properties that exists actually do as well as some documentation on how I can use them in combination with spring cloud?
  7. Do I need specific properties to enable my apps/clients to find other apps/clients?

Edited information

Thank you for your quick and excellent reply, I've gone through this over and over today and I finally got my application working.. The problem (I can't understand why and was hoping you could help me understand that) is that my discovery service contains yml files for each of my other clients where I specify things like port and eureka information.. What I specified here as well was:

eureka:
    client:
        serviceUrl:
            defaultZone: http://localhost:8761/eureka

So, when I set this value it seems to override something that makes my service discovery not working.. Even tho I can see all my applications in the eureka server, they were unable to find each other when I had this value set.

I set this value by having a message-server.yml file in my configuration service that is sent out to my message-server application after bootstrap..

So then I have two new questions.

  1. How do I override this eureka server property?
  2. Why does my discovery client stop working when I set this value, what is it that it actually does?
Dave Syer

What is required to actually use ribbon load balancer?

The ribbon-loadbalancer must be on the classpath (e.g. via "spring-cloud-starter-ribbon"). Then you can inject one as a LoadBalancerClient or you can inject a RestTemplate (it will be load-balancer aware if you have a LoadBalancerClient).

Do I have to use ribbon to be able to use the "auto discovery", I thought not but now I'm just confused.

What is "auto discovery"? You don't need to use Ribbon to use the DiscoveryClient (Ribbon is a load balancer, not a service registry).

From what I've understood, when using EnableEurekaClient I should not need to use the EnableDiscoveryClient as well?

Correct. @EnableEurekaClient is annotated with @EnableDiscoveryClient so it is only there to express a preference.

Can I change the yml files on my config-server for the clients in runtime and just have to reboot the client?

Yes. Or you can use the /refresh or /restart endpoints (a full reboot is probably best in production, at least periodically).

How much configuration is really meant to be shared by the config-server, because currently all of my clients just contain a super basic bootstrap.yml file.

As much as you want. How long is a piece of string? If I were you I would try and keep the central config to a minimum (only the things that change between environments, or at runtime).

Does anyone have a good link to where I can read more about all the properties that is being set in my yml files? Both a documentation of what the properties that exists actually do as well as some documentation on how I can use them in combination with spring cloud?

Spring Boot and Spring Cloud have autogenerated metadata for externalized properties. The new generation of IDEs understands them (so get STS 3.6.4 or IDEA 14.1), and they are listed in the user guide (for Spring Boot at least) under http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#common-application-properties

Do I need specific properties to enable my apps/clients to find other apps/clients?

You need to be able to locate your service registry (Eureka in this case). If you are using Eureka and your clients have registered then that is enough.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to selectively disable Eureka discovery client with Spring?

From Dev

How to Register Node app with Spring Cloud and Netflix's Eureka

From Dev

Spring Cloud Eureka: changing heartbeat and discovery path

From Dev

Spring cloud eureka client to multiple eureka servers

From Dev

Spring Cloud Netflix - how to access Eureka/Ribbon from traditional web app?

From Dev

Override Hystrix properties when using Spring Cloud Netflix

From Dev

How to config multiple Eureka Servers from client in Spring Cloud

From Dev

JSONException using Netflix Eureka

From Dev

Spring Cloud: Microservice authentication works through Eureka Discovery, but not through Zuul

From Dev

Creating a Client/Service in Netflix Eureka

From Dev

Spring Cloud: Eureka Client registration/deregistration cycle

From Dev

How can I see the json coming from the client when using Spring-MVC?

From Dev

How can I get Global Logout working in a multi tenant SAML application using spring-security-saml?

From Dev

How can I get these queries to work together?

From Dev

Spring cloud Eureka error when running

From Dev

How can I have a CSS work only when I have two classes together using less?

From Dev

When using spring aop:around, how can I get return type of the pointcut method?

From Dev

What is Spring Boot config to use Cloud Foundry Service Registry (Netflix Eureka) Service?

From Dev

Getting more detail from the Spring cloud Discovery Client

From Dev

eureka service discovery client in different languages

From Dev

Has the /eureka/v2/apps been removed from spring cloud discovery dashboard

From Dev

How to configure a custom RestTemplate when using spring-cloud-config-client?

From Dev

How to configure a custom RestTemplate when using spring-cloud-config-client?

From Dev

Spring cloud : Can not get Feign client to work with consul

From Dev

Spring cloud : Can not get Feign client to work with consul

From Dev

When using nginx, how can I get the $scheme using lua?

From Dev

Spring Cloud Config Eureka-first approach not working

From Dev

How can I use Netflix on Ubuntu?

From Dev

How can I use Netflix on Ubuntu?

Related Related

  1. 1

    How to selectively disable Eureka discovery client with Spring?

  2. 2

    How to Register Node app with Spring Cloud and Netflix's Eureka

  3. 3

    Spring Cloud Eureka: changing heartbeat and discovery path

  4. 4

    Spring cloud eureka client to multiple eureka servers

  5. 5

    Spring Cloud Netflix - how to access Eureka/Ribbon from traditional web app?

  6. 6

    Override Hystrix properties when using Spring Cloud Netflix

  7. 7

    How to config multiple Eureka Servers from client in Spring Cloud

  8. 8

    JSONException using Netflix Eureka

  9. 9

    Spring Cloud: Microservice authentication works through Eureka Discovery, but not through Zuul

  10. 10

    Creating a Client/Service in Netflix Eureka

  11. 11

    Spring Cloud: Eureka Client registration/deregistration cycle

  12. 12

    How can I see the json coming from the client when using Spring-MVC?

  13. 13

    How can I get Global Logout working in a multi tenant SAML application using spring-security-saml?

  14. 14

    How can I get these queries to work together?

  15. 15

    Spring cloud Eureka error when running

  16. 16

    How can I have a CSS work only when I have two classes together using less?

  17. 17

    When using spring aop:around, how can I get return type of the pointcut method?

  18. 18

    What is Spring Boot config to use Cloud Foundry Service Registry (Netflix Eureka) Service?

  19. 19

    Getting more detail from the Spring cloud Discovery Client

  20. 20

    eureka service discovery client in different languages

  21. 21

    Has the /eureka/v2/apps been removed from spring cloud discovery dashboard

  22. 22

    How to configure a custom RestTemplate when using spring-cloud-config-client?

  23. 23

    How to configure a custom RestTemplate when using spring-cloud-config-client?

  24. 24

    Spring cloud : Can not get Feign client to work with consul

  25. 25

    Spring cloud : Can not get Feign client to work with consul

  26. 26

    When using nginx, how can I get the $scheme using lua?

  27. 27

    Spring Cloud Config Eureka-first approach not working

  28. 28

    How can I use Netflix on Ubuntu?

  29. 29

    How can I use Netflix on Ubuntu?

HotTag

Archive