【问题标题】:How to Temporarily Disable Eureka Server support in Ribbon and FeignClient如何在 Ribbon 和 FeignClient 中临时禁用 Eureka Server 支持
【发布时间】:2020-02-28 20:57:07
【问题描述】:

我有两个微服务(car-management-service & rent-management-service) ,在 rent-management-service 中,我在帮助下通过 Ribbon 和 FeignClient 调用 car-management-service尤里卡发现服务器。它运行良好。

我已经启动了三个运行在端口 (8100,8101,8102) 上的 car-management-service 实例,而 Eureka 一个接一个地完美地提供了这三个实例.

现在我想尝试是否可以通过禁用(临时-只是为了测试是否可能)Eureka 并提供 car-management- 的直接 URL 来限制它只调用其中两个实例服务 个实例,同时仍然保留 Ribbon 和 FeignClient。

rent-management-service

application.yml的一部分
eureka:
  client:
    service-url:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
car-management-service:
  ribbon:
    eureka:
      enabled: false
    listOfServers: localhost:8100, localhost:8101
    #listOfServers: localhost:8100, localhost:8101, localhost:8102
    ServerListRefreshInterval: 1000

car-management-service

application.yml的一部分
server:
  port: 8100
eureka:
  client:
    enabled: true
    service-url:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}  

即使我在 rent-management-service 中禁用了 Eureka 以发现 car-management-service实例并硬编码三个正在运行的 car-management-service 实例中的两个,rent-management-service 仍然选择全部三个实例。

为什么会这样?是 application.yml 配置有问题还是 rent-management-service 仍然选择了所有三个 car-management-service 实例,因为它们在 pom.xml 中有 Eureka 服务器依赖项?

【问题讨论】:

  • 在rent-managment-service中尝试使用->ribbon.eureka.enabled: false 代替 car-management-service.ribbon.eureka.enabled: false
  • @DavidAraujo 如果我这样做,它不会在整个租赁管理服务中禁用 Eureka 服务支持吗?包括在 Feign&Ribbon 的帮助下在租车服务中使用的所有其他服务(除了 car-management-service)?我只想为 car-management-service 限制/硬编码两个实例

标签: spring-boot netflix-eureka spring-cloud-feign netflix-ribbon


【解决方案1】:

如果我理解正确,您希望汽车管理服务中的第三个实例不要从发现服务中获取流量。不是吗?你运行了 3 个实例,但你想让一个远离尤里卡? 你可以这样做。 从 car-management-service 运行 2 个实例,并在第 3 个实例中添加波纹管属性

eureka:
  client:
    fetch-registry: false
    register-with-eureka: false

在这种情况下,第三个服务将不会在 eureka 注册。

【讨论】:

  • 谢谢@krishantha-dinesh,这解决了 car-management-service &rent-management-service 之间的问题,但这样做是第三次实例已过时,对吗?没有其他服务也不能使用 car-management-service 的第三个实例。我正在寻找一种方法来禁用 eureka 的帮助并硬编码与 rent-management-servicecar-management-service 的 2 个实例/b>,但所有三个实例仍将由 rent-management-service 以外的服务使用。
猜你喜欢
  • 2018-09-20
  • 2020-10-15
  • 2016-03-06
  • 2018-11-17
  • 2020-11-02
  • 2019-09-18
  • 2015-12-12
  • 1970-01-01
  • 2019-08-04
相关资源
最近更新 更多