Search code examples
restmicroservicesjhipster

How to make the Jhipster gateway REST requests the microservice?


In order to learn the awesome JHipster framework I'm trying to implement a simple jhipster microservice architecture in order to have the gateway REST request the microservice and the microservice request the database.

Firstly, I generate a microservice application (backend port 8081), a microservice gateway (frontend port 8080) and clone the jhipster registry. Secondly, I import the same jdl in both microservice and gateway. I've implemented an AppLoading component to populate the database in the backend.

I've already tried to :

  • configure SERVER_API_URL in webpack.commons.js with the backend url
  • change "api/" to "backend/" in my gateway/**/*.service.ts and backend/**/web.rest.*Resource.java but I obtain "Http failure response for http://localhost:9000/backend/mois: 404 Not Found"
  • Set the target "http://localhost:8081" in my proxy.conf.json

My code is available on github:

I launch all of them (with mvnw command) and all seems ok:

  • registry know the backend and the frontend
  • the gateway know the backend
  • backend's database is correctly populate

But, no backend data are available in the gateway. The gateway communicate with its owm h2 database port 8080 and doesn't REST request for the backend which owns my data!

My questions are :

  • How can I configure the gateway in order to make it requests the backend? I'm pretty confused because all tuto I've seen doesn't have to configure anything to make things work...
  • Why are there java files generated by import-jdl in my gateway when this is the backend which have to handle it? How to make the import-jdl generate only front files?
  • Is there a way to generate gateway entities based on the already generated backend entities?

I tried to give all the necessary information but ask me if something is missing.

Thanks a lot :-)


Solution

  • You need to specify the microservice name in the JDL. Currently, you generated the entities in both the gateway and microservice. When you specify the microservice name, the gateway will only generate the frontend code. Here's an example:

    entity A
    entity B
    
    microservice * with backend
    

    https://www.jhipster.tech/jdl/#microserviceoptions