如何处理从网关到 jhipster 注册表上的正确微服务的请求?

how to handle request from gateway to right microservice on jhipster registry?

我们使用了jhipster的微服务架构,生成了三个应用 啊, 微服务, 网关。 然后 运行 服务器上的 uaa 和 jhipster 注册表,我们还有一些全栈开发人员 谁想同时开发网关和微服务。

然后,他们将微服务和网关部署到位于远程服务器上的 jhipsterRegistery 上。 由于微服务重名,jhipsterregistery 无法处理从网关到 正确的微服务

如何解决这个问题?

Sharing registry and gateway is probably a bad idea. Full stack developers should 运行 the gateway and registry locally on their PC, only share UAA if you really want to share something.

If you still want to do it, you could get inspired by how to manage multiple versions of a web API on a gateway. After all, in your case, each developer wants to use his/her own version of the API.

  • From client side, this can be done through URL or through an HTTP header. This means that you are able to configure client code to require a specific version.
  • This extra information in request would then get used by gateway for routing to the service that matches the requested version.
  • This works only if Zuul proxy in gateway knows about which version is supported by which service instance. It means that each instance must add this version information to their Eureka regsitration.

Here are 2 ideas that you could try:

  1. version in URL: define a spring profile (e.g. user) and use it to set a different application name in bootstrap-user.yml
  2. version in header: add some 属性 to Eureka metadata map (eureka.instance.metadataMap in bootstrap.yml) and modify the gateway so that it uses this info for routing.

Have a look at Spring Cloud Eureka server docs to get a good understanding about how this works and you could get even better ideas.

Here is an article about API versioning that could inspire you too: https://tech.asimio.net/2017/03/06/Multi-version-Service-Discovery-using-Spring-Cloud-Netflix-Eureka-and-Ribbon.html

我们遇到了同样的问题,并通过使用变量作为微服务应用程序名称解决了我们的问题。然后使用此变量更改网关中的所有其余 URL。 因此,每个开发人员只需在微中更改 application.yml 中的应用程序名称,就像网关中 app.constants.ts 中的变量一样。