简体   繁体   English

如何使用jhipster-registry动态地将请求流量从旧服务器实例切换到新服务器实例?

[英]How to switch request traffic from old server instance to a new one dynamically with jhipster-registry?

I use jhipster-registry for registry and manage microservice .And it based on Spring Cloud Netflix Eureka and Spring Cloud Config. 我使用jhipster-registry进行注册并管理微服务。它基于Spring Cloud Netflix Eureka和Spring Cloud Config。

when I add new api and publish next version of a micro service , I need 当我添加新的api并发布微服务的下一个版本时,我需要

  1. start a new service instance 启动一个新的服务实例
  2. switch request traffic from old instance to the new one 将请求流量从旧实例切换到新实例
  3. remove / shut down old one 删除/关闭旧的

And I don't want to restart my gateway during these steps. 我不想在这些步骤中重启我的网关。 Actually, I'm look a runtime dynamic routing method . 实际上,我看起来是一个运行时动态路由方法。

eureka 尤里卡

Unfortunately, this is not that easy, as Eureka favors availability over consistency, so it happens, that your service discovery consists of services, which are dead. 不幸的是,这并不容易,因为Eureka倾向于提供可用性而不是一致性,所以碰巧,您的服务发现包含已经死亡的服务。 A workaround I prefer to use with eurka is to set the MaxAutoRetries property higher for all application (what is easy, as JHipster Registry is a config server, so i share this for all), like 我更喜欢与eurka​​一起使用的解决方法是为所有应用程序设置更高的MaxAutoRetries属性(这很简单,因为JHipster Registry是一个配置服务器,所以我为所有人分享这个),就像

ribbon:
  ConnectTimeout: 3000
  ReadTimeout: 60000
  MaxAutoRetries: 10

so this at least make your request succeed after time during a deployment. 所以这至少会使您的请求在部署期间成功。 You will suffer some latency, as the first tries will go ahead to the old service, which is timing out...but no restarts are needed and your new services get online approx. 您将遇到一些延迟,因为第一次尝试将继续到旧服务,这是超时...但不需要重新启动,您的新服务大约在线。 3 - 5 minutes after deploy (this is my experience...it may differ from case to case) 部署后3 - 5分钟(这是我的经验......可能因情况而异)

consul 领事

As an alternative you might consider to switch to Hashicorps consul instead of eureka, which favors consistency, so you will be able to manage and sync your service discovery as soon as you deploy. 作为替代方案,您可以考虑切换到Hashicorps consul而不是eureka,这有利于一致性,因此您可以在部署后立即管理和同步服务发现。

Currently JHipster does only provide BETA support for consul, becaue it is not possible to run a fully secure installation, because of this bug where I am waiting for the review of the fix 目前JHipster并只提供测试版支持领事,becaue它不是可以运行一个完全安全的安装,因为这个错误在那里我在等待审查修复

It is actually easy to achieve what you want : 它实际上很容易实现你想要的:

  • Deploy two versions of your service with different instanceIds for example service-v1 and service-v2 . 使用不同的instanceIds部署两个版本的服务,例如service-v1service-v2 This is easy to achieve with setting eureka.instance.instanceId . 设置eureka.instance.instanceId很容易实现。

  • Initialy your Zuul Gateway is is proxying requests to service-v1 with the following properties present in your config server's gateway.yml: 最初,您的Zuul Gateway正在代理对service-v1的请求,并且配置服务器的gateway.yml中存在以下属性:

 zuul: routes: service: path: /service/** serviceId: service-v1 
  • Change the config server zuul configuration to this: 将配置服务器zuul配置更改为:
 zuul: routes: service: path: /service/** serviceId: service-v2 
  • Then trigger a refresh of the gateway's config: 然后触发刷新网关的配置:
 curl -X POST http://localhost:8080/management/refresh 

(note that this endpoint is secured so you will need to pass it a token to pass through) (请注意,此端点是安全的,因此您需要传递一个令牌才能通过)

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

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