Leila Mollaei
Leila Mollaei

Reputation: 43

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

we used microservice architecture of jhipster and generated three applications uaa, microservice, gateway. then run uaa and jhipster registry on a server, also we have some full stack developers who want to develop both gateway and microservice at the same time.

then, they deploy their microservice and gateway on jhipsterRegistery which is located on remote server. Because of the same name of microservices, jhipsterregistery can not handle requests from gateway to the right microservice

how to manage this problem?

Upvotes: 3

Views: 637

Answers (2)

Hosi Jafari
Hosi Jafari

Reputation: 88

We had the same problem and solved our issue by using a variable as a microservice application name. Then changed all rest URLs in gateway with this variable. So each developer just needs to change appname in application.yml in micro the same as the variable in app.constants.ts in the gateway as well.

Upvotes: 1

Gaël Marziou
Gaël Marziou

Reputation: 16284

Sharing registry and gateway is probably a bad idea. Full stack developers should run 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 property 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

Upvotes: 0

Related Questions