简体   繁体   English

在尤里卡注册我的配置服务器有什么用吗?

[英]Is there any use of registering my config server in Eureka?

I'm specifying the config server URI spring.cloud.config.uri in the bootstrap.properties file of all my config server clients.我在所有配置服务器客户端的bootstrap.properties文件中指定了配置服务器 URI spring.cloud.config.uri

So is there any use of adding an @EnableDiscoveryClient annotation to it, and registering the configuration service in Eureka?那么给它添加一个@EnableDiscoveryClient注解,在Eureka中注册配置服务有什么用呢?

There are various use cases why registering your config server on Eureka could be useful:在 Eureka 上注册您的配置服务器可能会有用的原因有多种:

Discovery-first bootstrapping发现优先引导

When using the Spring cloud config service, you have two choices when bootstrapping your application, as mentioned by the documentation :使用 Spring 云配置服务时,在引导应用程序时有两种选择,如文档所述

  1. Using a config-first setup (default)使用配置优先设置(默认)
  2. Using a discovery-first setup使用发现优先设置

When you use a discovery-first setup, all applications can retrieve their configuration by looking up the URL of the configuration service on Eureka:当您使用发现优先设置时,所有应用程序都可以通过在 Eureka 上查找配置服务的 URL 来检索其配置:

spring.cloud.config.discovery.enabled=true
spring.cloud.config.uri=http://config-service

In this case, the application will look for a service named config-service on Eureka, and will use the given hostname and port to connect.在这种情况下,应用程序将在 Eureka 上查找名为config-service ,并将使用给定的主机名和端口进行连接。


Discoverability可发现性

Some tools, like Zuul, Spring boot admin, ... will automatically discover all applications and use them, for example:一些工具,如 Zuul、Spring boot admin 等,会自动发现所有应用程序并使用它们,例如:

  • Spring boot admin can be setup to automatically discover all applications to manage them. Spring boot admin 可以设置为自动发现所有应用程序来管理它们。
  • Zuul will automatically forward all routes matching /{application-name}/** to the given application. Zuul 会自动将所有匹配/{application-name}/**路由转发到给定的应用程序。

@EnableDiscoveryClient activates the Netflix Eureka DiscoveryClient implementation and tells it to register itself with a service registry. @EnableDiscoveryClient激活Netflix Eureka DiscoveryClient实现并告诉它向服务注册表注册自己。

So, without this annotation, your application will not able to register itself to any Registry.因此,如果没有此注释,您的应用程序将无法将自己注册到任何注册表。 And hence will not be discovered from any service as well.因此也不会被任何服务发现。


Edit : Registering your application to DiscoveryServer provides many benefits, some of them are below :编辑:将您的应用程序注册到DiscoveryServer提供了许多好处,其中一些如下:

  • Application independence : When you register your application to DiscoveryServer it decouples it from another application.应用程序独立性:当您将应用程序注册到 DiscoveryServer 时,它会将其与另一个应用程序分离。 Doing so you don't need to hardcode the name and URL of your application in using application.这样做您不需要在使用 application.properties 时对应用程序的名称和 URL 进行硬编码。
  • Load Balancing : Register your application to DiscoveryServer provides an effective and efficient way to provide load balancing.负载平衡:将您的应用程序注册到 DiscoveryServer 提供了一种有效且高效的方式来提供负载平衡。
  • Multiple instances of same application : In order to provide load balancing you can add multiple instances of a single application.同一应用程序的多个实例:为了提供负载平衡,您可以添加单个应用程序的多个实例。
  • Resilience : When an instance is not working then Server can use the circuit breaker to handle requests effectively and helps in making system responsive and resilient.弹性:当实例不工作时,服务器可以使用断路器有效地处理请求,并有助于使系统具有响应性和弹性。

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

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