简体   繁体   English

在没有数据库的 JHipster 微服务架构中创建网关

[英]Creating a Gateway in JHipster microservice arhitecture without database

I am trying out JHipster based on the supported Microservice architecture.我正在尝试基于支持的微服务架构的 JHipster。 I have created a Registry, Gateway, and a Microservice (based on JWT authentication) as described in documentation and everything works.我创建了一个注册表、网关和一个微服务(基于 JWT 身份验证),如文档中所述,一切正常。 However I am not sure why a Gateway in JHispter need to have a database.但是我不确定为什么 JHispter 中的网关需要有一个数据库。 Questions that are still unanswered for me: 1- Why does a Gateway need a database?我仍然没有回答的问题: 1- 为什么网关需要数据库? In which scenarios would you create a Gateway with/without a database?在哪些情况下,您会创建一个带/不带数据库的网关? 2- Do the Gateway and Microservice use the same database? 2-网关和微服务是否使用相同的数据库? Or should they use separate database instances?或者他们应该使用单独的数据库实例?

1) A gateway using JWT or OAuth2 auth types need a database to store users and their account details. 1) 使用 JWT 或 OAuth2 身份验证类型的网关需要一个数据库来存储用户及其帐户详细信息。 A gateway using UAA auth type does not need a database, because the UAA microservice handles users and authentication.使用 UAA 身份验证类型的网关不需要数据库,因为 UAA 微服务处理用户和身份验证。

2) Gateways and microservices should use their own database instances. 2)网关和微服务应该使用自己的数据库实例。 You can use the same database instance in dev , but in prod each should have their own.您可以在dev中使用相同的数据库实例,但在prod中每个都应该有自己的。

You can generate a docker-compose or kubernetes config for your gateway/microservices with the JHipster subgenerators, and in the generated YML files you will see each app has its own database instance.您可以使用 JHipster 子生成器为您的网关/微服务生成docker-composekubernetes配置,在生成的 YML 文件中,您将看到每个应用程序都有自己的数据库实例。

Ok, I did a bit more research on JHipster-Gateway and the inner workings of it.好的,我对 JHipster-Gateway 及其内部工作进行了更多研究。 Below is a summary, related to my question:以下是与我的问题相关的摘要:

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. 1- 使用 JWT 或 Oauth2 类型的网关仅在网关代码库中也生成用户相关实体和后端代码时才需要数据库。 This is the case for a default JHipster Gateway, but does not have to be like this.这是默认 JHipster 网关的情况,但不必是这样。 As indicated in JHipster documentation a JHipster Gateway is actually a monolithic application and can be used as a monolithic application:如 JHipster 文档中所示,JHipster 网关实际上是一个单体应用程序,可以用作单体应用程序:

You will have the choice either to generate an new entity normally (a gateway is also a standard JHipster application, so this would work like for a monolith application), or use an existing JHipster configuration from a microservice.您可以选择正常生成一个新实体(网关也是标准的 JHipster 应用程序,因此这将像单体应用程序一样工作),或者使用来自微服务的现有 JHipster 配置。

When you create a JHipster Gateway, it creates the User entity related backend in Gateway codebase as default.当您创建 JHipster 网关时,它默认在网关代码库中创建与用户实体相关的后端。 But you can choose to have all the Backend code (including User) be placed/generated in Microservice codebase.但是您可以选择将所有后端代码(包括用户)放置/生成在微服务代码库中。

In such case there is no need of a database in JHipster Gateway application.在这种情况下,JHipster Gateway 应用程序中不需要数据库。 Gateway working purely as a gateway to pass requests to microservices only needs to have the /api configurations properly set.网关纯粹用作将请求传递给微服务的网关,只需要正确设置 /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.在 JHipster 网关的默认情况下,用户实体后端代码也在网关部分生成,这就是需要数据库的原因。 But you can move the backend code to Microservice and replace it by a proper /api configuration.但是您可以将后端代码移动到微服务并用适当的 /api 配置替换它。

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

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