简体   繁体   中英

How to configure Eureka Client and Service properties?

I'm trying to register my Java service with Eureka - with no luck. I have an existing code base that uses Spark-Java framework, so that 'add only 2 lines of Spring annotations and voila!' examples unfortunately are not helpful for me.

I read the Eureka Configuration documentation, created a eureka-conf directory and put the following two files in eureka-conf:

  • eureka-client.properties
  • eureka-service.properties

I added the eureka_conf path to my $CLASSPATH variable with export CLASSPATH=.:${CLASSPATH}:${EUREKA_CONF}/eureka-client.properties:${EUREKA_CONF}/eureka-service.properties

I copy-pasted the content of the property files from here . So, they look like this:

#eureka-client.properties
eureka.registration.enabled=false
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:8080/eureka/v2/
eureka.decoderName=JacksonJson

#eureka-service.properties
eureka.region=us-west-1
eureka.name=qb-acm
eureka.vipAddress=mysampleservice.mydomain.net
eureka.port=8001
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:8080/eureka/v2/

You can see, I changed the eureka.name and eureka.region to see in the logs if the properties are being found or not. They are not found.

When I start my service I see the com.netflix.discovery.internal.util.Archaius1Utils throws the following warning:

Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.

Followed by this: INFO com.netflix.discovery.DiscoveryClient - Initializing Eureka in region us-east-1 .

I've created an example Eureka Server and Client (with Spring) just to do an example and the Spring client is registered. Now, I'm trying to have my non-Spring Java service register with the local Eureka server. My end goal is to set this service to register and send heart beats to our remote Eureka server which is being hosted on Pivotal.

Other errors might be useful to the reader:

[main] ERROR com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver - Cannot resolve to any endpoints from provided configuration: {defaultZone=[]}
[main] ERROR com.netflix.discovery.shared.transport.EurekaHttpClients - Initial resolution of Eureka server endpoints failed. Check ConfigClusterResolver logs for more info

So, my questions are:

  1. What am I doing wrong setting the properties?

  2. I see in many examples they have an application.yml or manifest.yml file. What is the .yaml file for in Eureka configuration? Is it an alternative to the property files?

edit: I found this answer explains the yaml files. Application.yml is used by Spring boot and Manifest.yml is used by cloud foundry CLI.

  1. What should be eureka.vipAddress on my local environment and on Pivotal?

**edit: I found out, with trial and error, on local this is set to http://localhost:yourport and for PCF it should be the application name. Neither localhost nor service-name corresponds to a physical network interface. Oh well, I finally learned what a virtual ip is **

Let me know if more information needed. Thanks in advance for any help.

It seems, that your config files are not found during startup. The eureka configuration files must be on the classpath. Sometimes they are not packaged to the jar file. Be sure to have the files in your jar (try jar xf <your-jar-file> to analyze the content of your jar.

Are you building with maven? Then add a resource/include block in the build section of your pom-File to ensure the inclusion of the config files.

Some of the eureka properties can be set in the application.yml files which is the same as applicaiton.properties except for the format you are writing your configurations. I am not sure if there is a eureka-client.properties equivalent for yaml. First get the *.properties running, then try if it understands yaml.

eureka-client.properties and eureka-service.properties in classpath works for me. I have put these files in resources directory of my Web Application. These files are used by Eureka Client and Eureka Server.

application.yml is used by Spring Cloud implementation and is a separate way of working with Eureka registry or any other registry for that matter.

vipAddress is kind of a name by which your application will be registered in Eureka.

The service which registers itself will have eureka.registration.enabled=true in eureka-client.properties. It seems all service registration properties are picked up from this file only. The service which does discovery only will have eureka.registration.enabled=false in its eureka-client.properties

Following link provides a sample application that does registration and discovery:
https://github.com/Netflix/eureka/tree/master/eureka-examples

Please not that there are three components involved here
1) Eureka Server
2) Service (Uses Eureka Client) - which does registration
3) Client (Uses Eureka Client) - which does discovery

The above example talks about 2 and 3. To launch a Eureka service you can go through the following link which will ask you to build Eureka Server war file and drop it on a Tomcat server.
https://github.com/Netflix/eureka/wiki/Building-Eureka-Client-and-Server

In order to do your testing you can directly query Eureka Server using its REST interface with an http client like curl or a browser.
https://github.com/Netflix/eureka/wiki/Eureka-REST-operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM