简体   繁体   English

如何使Jhipster网关REST请求微服务?

[英]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. 为了学习很棒的JHipster框架,我试图实现一个简单的jhipster微服务架构,以使网关REST请求微服务,而微服务请求数据库。

Firstly, I generate a microservice application (backend port 8081), a microservice gateway (frontend port 8080) and clone the jhipster registry. 首先,我生成一个微服务应用程序(后端端口8081),一个微服务网关(前端端口8080)并克隆jhipster注册表。 Secondly, I import the same jdl in both microservice and gateway. 其次,我在微服务和网关中都导入了相同的jdl。 I've implemented an AppLoading component to populate the database in the backend. 我已经实现了一个AppLoading组件,以在后端填充数据库。

I've already tried to : 我已经尝试过:

  • configure SERVER_API_URL in webpack.commons.js with the backend url 使用后端URL在webpack.commons.js中配置SERVER_API_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" 在我的网关/**/*.service.ts和backend / ** / web.rest。* Resource.java中将“ api /”更改为“ backend /”,但是我获得了“ http:// localhost的 Http故障响应: 9000 /后端/ mois :找不到404”
  • Set the target " http://localhost:8081 " in my proxy.conf.json 在我的proxy.conf.json中设置目标“ http:// localhost:8081

My code is available on github: 我的代码在github上可用:

I launch all of them (with mvnw command) and all seems ok: 我启动了所有它们(使用mvnw命令),并且一切正常:

  • 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! 网关与其owm h2数据库端口8080通信,并且不对拥有我的数据的后端进行REST请求!

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... 我很困惑,因为我所见过的所有tuto都不需要进行任何配置即可使工作正常...
  • Why are there java files generated by import-jdl in my gateway when this is the backend which have to handle it? 当后端必须处理它时,为什么网关中的import-jdl会生成java文件? How to make the import-jdl generate only front files? 如何使import-jdl仅生成前端文件?
  • 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 :-) 非常感谢 :-)

You need to specify the microservice name in the JDL. 您需要在JDL中指定microservice名称。 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 https://www.jhipster.tech/jdl/#microserviceoptions

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

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