简体   繁体   English

如何配置 Eureka Client 和 Service 属性?

[英]How to configure Eureka Client and Service properties?

I'm trying to register my Java service with Eureka - with no luck.我正在尝试向 Eureka 注册我的 Java 服务 - 没有运气。 I have an existing code base that uses Spark-Java framework, so that 'add only 2 lines of Spring annotations and voila!'我有一个使用 Spark-Java 框架的现有代码库,因此“仅添加 2 行 Spring 注释,瞧!” 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 配置文档,创建了一个 eureka-conf 目录并将以下两个文件放在 eureka-conf 中:

  • eureka-client.properties eureka-client.properties
  • eureka-service.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我使用export CLASSPATH=.:${CLASSPATH}:${EUREKA_CONF}/eureka-client.properties:${EUREKA_CONF}/eureka-service.properties添加了 eureka_conf 路径到我的 $CLASSPATH 变量

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.您可以看到,我更改了 eureka.name 和 eureka.region 以在日志中查看是否找到了属性。 They are not found.他们没有被发现。

When I start my service I see the com.netflix.discovery.internal.util.Archaius1Utils throws the following warning:当我启动我的服务时,我看到com.netflix.discovery.internal.util.Archaius1Utils抛出以下警告:

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 .其次是: 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.我创建了一个示例 Eureka 服务器和客户端(使用 Spring)只是为了做一个示例并且注册了 Spring 客户端。 Now, I'm trying to have my non-Spring Java service register with the local Eureka server.现在,我正在尝试将我的非 Spring Java 服务注册到本地 Eureka 服务器。 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.我的最终目标是将此服务设置为注册并将心跳发送到我们托管在 Pivotal 上的远程 Eureka 服务器。

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.我在很多例子中看到他们有一个application.ymlmanifest.yml文件。 What is the .yaml file for in Eureka configuration? Eureka 配置中的 .yaml 文件是什么? Is it an alternative to the property files?它是属性文件的替代品吗?

edit: I found this answer explains the yaml files.编辑:我发现这个答案解释了 yaml 文件。 Application.yml is used by Spring boot and Manifest.yml is used by cloud foundry CLI. Application.yml 由 Spring boot 使用,Manifest.yml 由 cloud foundry CLI 使用。

  1. What should be eureka.vipAddress on my local environment and on Pivotal?我的本地环境和 Pivotal 上的 eureka.vipAddress 应该是什么?

**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. **编辑:我通过反复试验发现,在本地设置为http://localhost:yourport ,对于 PCF,它应该是应用程序名称。 Neither localhost nor service-name corresponds to a physical network interface. localhostservice-name都不对应于物理网络接口。 Oh well, I finally learned what a virtual ip is **哦,我终于知道什么是虚拟 ip **

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. eureka 配置文件必须在类路径上。 Sometimes they are not packaged to the jar file.有时它们没有打包到 jar 文件中。 Be sure to have the files in your jar (try jar xf <your-jar-file> to analyze the content of your jar.确保在你的 jar 中有这些文件(try jar xf <your-jar-file>来分析你的 jar 的内容。

Are you building with maven?你是用maven构建的吗? Then add a resource/include block in the build section of your pom-File to ensure the inclusion of the config files.然后在 pom 文件的构建部分添加一个资源/包含块,以确保包含配置文件。

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.一些 eureka 属性可以在 application.yml 文件中设置,这与 applicaiton.properties 相同,除了您编写配置的格式。 I am not sure if there is a eureka-client.properties equivalent for yaml.我不确定是否有与 yaml 等效的 eureka-client.properties。 First get the *.properties running, then try if it understands yaml.首先让 *.properties 运行,然后尝试它是否理解 yaml。

eureka-client.properties and eureka-service.properties in classpath works for me.类路径中的 eureka-client.properties 和 eureka-service.properties 对我有用。 I have put these files in resources directory of my Web Application.我已将这些文件放在我的 Web 应用程序的资源目录中。 These files are used by Eureka Client and Eureka Server.这些文件由 Eureka Client 和 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. application.yml 由 Spring Cloud 实现使用,是与 Eureka 注册表或任何其他注册表一起工作的单独方式。

vipAddress is kind of a name by which your application will be registered in Eureka. vipAddress 是一种名称,您的应用程序将通过该名称在 Eureka 中注册。

The service which registers itself will have eureka.registration.enabled=true in eureka-client.properties.注册自己的服务将在 eureka-client.properties 中有 eureka.registration.enabled=true 。 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仅进行发现的服务在其 eureka-client.properties 中将具有 eureka.registration.enabled=false

Following link provides a sample application that does registration and discovery:以下链接提供了一个执行注册和发现的示例应用程序:
https://github.com/Netflix/eureka/tree/master/eureka-examples https://github.com/Netflix/eureka/tree/master/eureka-examples

Please not that there are three components involved here请注意这里涉及三个组件
1) Eureka Server 1)尤里卡服务器
2) Service (Uses Eureka Client) - which does registration 2) 服务(使用 Eureka 客户端) - 进行注册
3) Client (Uses Eureka Client) - which does discovery 3)客户端(使用 Eureka 客户端) - 进行发现

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.上面的例子谈到了 2 和 3。要启动一个 Eureka 服务,你可以通过以下链接,它会要求你构建 Eureka Server war 文件并将其放在 Tomcat 服务器上。
https://github.com/Netflix/eureka/wiki/Building-Eureka-Client-and-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.为了进行测试,您可以使用其 REST 接口和 curl 或浏览器等 http 客户端直接查询 Eureka 服务器。
https://github.com/Netflix/eureka/wiki/Eureka-REST-operations https://github.com/Netflix/eureka/wiki/Eureka-REST-operations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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