Creating a Gateway in JHipster microservice arhitecture without database

[亡魂溺海] 提交于 2019-12-12 01:28:50

问题


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?


回答1:


1) A gateway using JWT or OAuth2 auth types need a database to store users and their account details. A gateway using UAA auth type does not need a database, because the UAA microservice handles users and authentication.

2) Gateways and microservices should use their own database instances. You can use the same database instance in dev, but in prod each should have their own.

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.




回答2:


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- 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:

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.

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.

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.

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.



来源:https://stackoverflow.com/questions/58973682/creating-a-gateway-in-jhipster-microservice-arhitecture-without-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!