英文:
JHipster How to control entitie generation to microservice? or How to do JDL properly to get the entities generated into the right micorservice folder
问题
-
控制实体生成位置的确切方式是什么?
- 实体生成位置受
application
配置中的baseName
属性控制。在你的示例中,baseName
被设置为每个应用程序,例如gateway
、invoice
、usage
、order
。因此,每个应用程序的实体代码将生成在相应的应用程序目录下。
- 实体生成位置受
-
microservice <ENTITIES> with <MICROSERVICE_APP_NAME>
如何与上述的entities *
部分相关联?microservice <ENTITIES> with <MICROSERVICE_APP_NAME>
用于将特定的实体与微服务关联起来。在你的JDL文件中,你为不同的实体和微服务定义了关联,例如microservice Invoice with invoice
,microservice Usage with usage
,microservice Product, ProductCategory, ProductOrder, OrderItem with order
。这些关联定义了哪些实体将生成在哪个微服务中。
-
实体之间的关系是否会影响代码生成位置?
- 实体之间的关系通常不会直接影响代码生成位置。代码生成位置主要由每个实体的
application
配置中的baseName
属性决定。然而,关系可以影响生成的代码,因为它们可能需要在关联的实体之间生成特定的代码,如关联的存取方法。但是,关系本身不会决定代码生成的位置。
- 实体之间的关系通常不会直接影响代码生成位置。代码生成位置主要由每个实体的
英文:
I am trying to prototype a microservice application with JHipster and I have tried to collect all the information what I was able in order to do it properly, but it is not totally clear how to put together a JDL to have the right entities in the right services generated.
What I would expect is to have a directory layout like:
/..
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)
Here is the JDL used:
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:
##### **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!
So here are my questions:
1. What is exactly controlling where the entities are generated?
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. How is microservice <ENTITIES> with <MICROSERVICE_APP_NAME>
relates to the above mentioned entities *
section?
3. Is the relationship between entities affects where the code is generated?
答案1
得分: 1
-
从后端角度来看,实体不是在网关中生成的,只生成这些实体的前端代码。
-
网关使用它来路由到正确的微服务。
-
不能存在不同微服务之间的实体关系,因为它们存在于不同的数据库中。
英文:
-
Entities are not generated in a gateway from backend standpoint, only frontend code for these entities is generated
-
It's used by the gateway to route to correct microservice
-
There can't be any relationship between entities from different microservices because they reside in distinct databases
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论