JHipster 如何控制微服务的整体生成?或如何正确执行 JDL 以将生成的实体放入正确的 micorservice



我正在尝试使用JHipster对微服务应用程序进行原型设计,并且我试图收集所有信息,以便正确执行此操作,但是并不完全清楚如何将JDL放在一起以在正确的服务中生成正确的实体。

我期望的是有一个目录布局,如下所示:

/..
gateway <- Ideal would be to have only fronted code
invoice <- Invoice CRUD code with corresponding ms (with below JDL it is empty)
order <- Order CRUD code with corresponding ms
usage <- Usage CRUD code with corresponding ms (with below JDL it is empty)

以下是使用的 JDL:

application {
config {
baseName gateway,
applicationType gateway,
packageName com.org.myApp.sales,
serviceDiscoveryType eureka,
searchEngine elasticsearch,
authenticationType oauth2,
prodDatabaseType postgresql,
cacheProvider hazelcast,
buildTool gradle,
clientFramework react,
testFrameworks [protractor]
}
entities *
}
application {
config {
baseName invoice,
applicationType microservice,
packageName com.org.myApp.invoice,
serviceDiscoveryType eureka,
searchEngine elasticsearch,
authenticationType oauth2,
prodDatabaseType postgresql,
devDatabaseType postgresql,
buildTool gradle,
serverPort 8081,
skipUserManagement true
}
entities Invoice, Product
}
application {
config {
baseName usage,
applicationType microservice,
packageName com.org.myApp.usage,
serviceDiscoveryType eureka,
searchEngine elasticsearch,
authenticationType oauth2,
prodDatabaseType postgresql,
devDatabaseType postgresql,
cacheProvider no,
enableHibernateCache false,
buildTool gradle,
serverPort 8082,
skipUserManagement true
}
entities Usage
}
application {
config {
baseName order,
applicationType microservice,
packageName com.org.myApp.order,
serviceDiscoveryType eureka,
searchEngine elasticsearch,
authenticationType oauth2,
prodDatabaseType postgresql,
devDatabaseType postgresql,
buildTool gradle,
serverPort 8083,
skipUserManagement true
}
entities ProductOrder, OrderItem, ProductCategory, Product
}
entity Product {
name String required
description String
price BigDecimal required min(0)
size Size required
image ImageBlob
}
enum Size {
S, M, L, XL, XXL
}
entity ProductCategory {
name String required
description String
}
entity Customer {
firstName String required
lastName String required
gender Gender required
email String required pattern(/^[^@s]+@[^@s]+.[^@s]+$/)
phone String required
addressLine1 String required
addressLine2 String
city String required
country String required
}
enum Gender {
MALE, FEMALE, OTHER
}
entity ProductOrder {
placedDate Instant required
status OrderStatus required
code String required
invoiceId Long
}
enum OrderStatus {
COMPLETED, PENDING, CANCELLED
}
entity OrderItem {
quantity Integer required min(0)
totalPrice BigDecimal required min(0)
status OrderItemStatus required
}
enum OrderItemStatus {
AVAILABLE, OUT_OF_STOCK, BACK_ORDER
}
relationship OneToOne {
Customer{user(login) required} to User
}
relationship ManyToOne {
OrderItem{product(name) required} to Product
}
relationship OneToMany {
ProductOrder{orderItem} to OrderItem{order(code) required} ,
ProductCategory{product} to Product{productCategory(name)}
}
service Product, ProductCategory, Customer, ProductOrder, OrderItem with serviceClass
paginate Product, Customer, ProductOrder, OrderItem with pagination
/* Entities for Invoice microservice */
entity Invoice {
code String required
date Instant required
details String
status InvoiceStatus required
paymentMethod PaymentMethod required
paymentDate Instant required
paymentAmount BigDecimal required
}
enum InvoiceStatus {
PAID, ISSUED, CANCELLED
}
enum PaymentMethod {
CREDIT_CARD, CASH_ON_DELIVERY, PAYPAL
}
entity Usage {
date Instant required
details String
sentDate Instant required
userId Long required
productId Long required
}

microservice Invoice with invoice
microservice Usage with usage
microservice Product, ProductCategory, ProductOrder, OrderItem with order
dto * with mapstruct
paginate Invoice with pagination

环境:

##### **Environment and Tools**
JHipster version: v6.6.0
java version "11.0.5" 2019-10-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.5+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.5+10-LTS, mixed mode)
node: v12.14.0
npm: 6.13.4
yeoman: 3.1.1
INFO! Congratulations, JHipster execution is complete!

所以这是我的问题:

1. 究竟是什么控制实体的生成位置?

application { 
config {
baseName gateway,
applicationType gateway,
packageName com.org.myApp.sales,
serviceDiscoveryType eureka,
searchEngine elasticsearch,
authenticationType oauth2,
prodDatabaseType postgresql,
cacheProvider hazelcast,
buildTool gradle,
clientFramework react,
testFrameworks [protractor] 
} 
entities * <-- What if all entities associated to a different service not to the gateway? (actually when I tried I ended up with an empty folder for gateway)
}

2.microservice <ENTITIES> with <MICROSERVICE_APP_NAME>与上述entities *部分有何关系?

3. 实体之间的关系是否会影响代码的生成位置?

  1. 从后端的角度来看,不会在网关中生成实体,只会生成这些实体的前端代码

  2. 网关使用它来路由到正确的微服务

  3. 来自不同微服务的实体之间不能有任何关系,因为它们驻留在不同的数据库中

最新更新