简体   繁体   English

什么是春天尤里卡的instanceid?

[英]What is instanceid in spring eureka?

I read that instance id of Eureka Clients have to be unique and when we wish to run multiple instances of the same Eureka Client, then we add this property: 我读到Eureka客户端的实例ID必须是唯一的,当我们希望运行同一个Eureka Client的多个实例时,我们添加了这个属性:

eureka.instance.instance-id==${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

What is the significance of instance Id and how does the above line matter? 实例Id的意义是什么?上述行如何重要?

A Eureka Client has an app ID and an instance ID . Eureka客户端具有应用程序ID实例ID T he app ID is the name of the application while the instance ID is the unique id associated with the instance of the client . 应用程序ID是应用程序的名称,而实例ID是与客户端实例关联的唯一ID

This helps Eureka Server to make a distinction between different client instances of the same application. 这有助于Eureka Server 区分同一应用程序的不同客户端实例。 In your example, the line shown below sets up a unique instance ID for your application having format: <client host name>:<client app name>:<some random number> 在您的示例中,下面显示的行为您的应用程序设置了一个唯一的实例ID,其格式为: <client host name>:<client app name>:<some random number>

eureka.instance.instance-id==${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

In my example shown below, the instance ID has the format - <host name>:<app id>:<port> . 在下面显示的示例中,实例ID的格式为 - <host name>:<app id>:<port> The Eureka REST operation shown below will change the status of eureka client with app ID of AUTHOR and instance ID of 10.16.6.76:author:8766 to OUT_OF_SERVICE . 下面显示的Eureka REST操作将使用应用程序ID AUTHOR和实例ID 10.16.6.76:author:8766OUT_OF_SERVICE客户端的状态更改为OUT_OF_SERVICE

localhost:8761/eureka/apps/AUTHOR/10.16.6.76:author:8766/status?value=OUT_OF_SERVICE 

If you noticed, Eureka Server can uniquely identify a client if you provide both the application ID and the instance ID. 如果您注意到,如果同时提供应用程序ID和实例ID,Eureka Server可以唯一标识客户端。

在此输入图像描述

It is used to uniquely ID a single instance of multiple services Eg if you deployed 2x instances of the same spring boot application the instance ID is used to distinguish between them. 它用于唯一地标识多个服务的单个实例。例如,如果您部署了同一个春季启动应用程序的2x实例,则使用实例ID来区分它们。

Some additional use cases for PCF and AWS w/ Instance ID can be found in the documentation. 可以在文档中找到PCF和AWS w / Instance ID的一些其他用例。

https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html https://cloud.spring.io/spring-cloud-netflix/multi/multi__service_discovery_eureka_clients.html

The above property simply takes the other properties, combines them. 上面的属性简单地采用其他属性,将它们组合在一起。 The only gotcha above is that if a spring.application_instance_id is not found in the environment it will use a random.value instead. 上面唯一的问题是,如果在环境中找不到spring.application_instance_id ,它将使用random.value代替。 You can override however you like but it should be unique. 您可以根据自己的喜好进行覆盖,但它应该是唯一的。

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

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