问题描述
我正在基于受支持的微服务体系结构试用JHipster.如文档中所述,我已经创建了注册表,网关和微服务(基于JWT身份验证),并且一切正常.但是我不确定JHispter中的网关为什么需要数据库.对我来说仍然没有答案的问题:1-为什么网关需要数据库?在哪种情况下,您将创建带有/不带有数据库的网关?2-网关和微服务是否使用相同的数据库?还是应该使用单独的数据库实例?
I am trying out JHipster based on the supported Microservice architecture. I have created a Registry, Gateway, and a Microservice (based on JWT authentication) as described in documentation and everything works. However I am not sure why a Gateway in JHispter need to have a database. Questions that are still unanswered for me:1- Why does a Gateway need a database? In which scenarios would you create a Gateway with/without a database?2- Do the Gateway and Microservice use the same database? Or should they use separate database instances?
推荐答案
好,我对JHipster-Gateway及其内部功能进行了更多研究.以下是与我的问题有关的摘要:
Ok, I did a bit more research on JHipster-Gateway and the inner workings of it. Below is a summary, related to my question:
1-使用JWT或Oauth2类型的网关仅在网关代码库中还生成了与用户相关的实体和后端代码的情况下,才需要数据库.默认的JHipster网关就是这种情况,但不必如此.如JHipster文档中所述,JHipster网关实际上是一个整体应用程序,可以用作整体应用程序:
1- A Gateway using a JWT or Oauth2 type only needs a database if the User related entities and backend code are also generated in the Gateway codebase. This is the case for a default JHipster Gateway, but does not have to be like this. As indicated in JHipster documentation a JHipster Gateway is actually a monolithic application and can be used as a monolithic application:
创建JHipster网关时,它将默认在网关代码库中创建与用户实体相关的后端.但是您可以选择在Microservice代码库中放置/生成所有后端代码(包括用户).
When you create a JHipster Gateway, it creates the User entity related backend in Gateway codebase as default. But you can choose to have all the Backend code (including User) be placed/generated in Microservice codebase.
在这种情况下,JHipster Gateway应用程序中不需要数据库.网关纯粹用作将请求传递给微服务的网关,只需要正确设置/api配置即可.
In such case there is no need of a database in JHipster Gateway application. Gateway working purely as a gateway to pass requests to microservices only needs to have the /api configurations properly set.
在JHipster网关的默认情况下,还会在网关部分生成用户实体后端代码,这就是需要数据库的原因.但是您可以将后端代码移至微服务,并用适当的/api配置替换它.
In the default case of a JHipster Gateway the User entity backend code is also generated in Gateway part, that is the reason why a database is needed. But you can move the backend code to Microservice and replace it by a proper /api configuration.
这篇关于在没有数据库的JHipster微服务架构中创建网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!