JHipster How to control entitie generation to microservice? or How to do JDL properly to get the entities generated into the right micorservice folder

huangapple go评论58阅读模式
英文:

JHipster How to control entitie generation to microservice? or How to do JDL properly to get the entities generated into the right micorservice folder

问题

  1. 控制实体生成位置的确切方式是什么?

    • 实体生成位置受application配置中的baseName属性控制。在你的示例中,baseName被设置为每个应用程序,例如gatewayinvoiceusageorder。因此,每个应用程序的实体代码将生成在相应的应用程序目录下。
  2. microservice <ENTITIES> with <MICROSERVICE_APP_NAME> 如何与上述的 entities * 部分相关联?

    • microservice <ENTITIES> with <MICROSERVICE_APP_NAME> 用于将特定的实体与微服务关联起来。在你的JDL文件中,你为不同的实体和微服务定义了关联,例如 microservice Invoice with invoicemicroservice Usage with usagemicroservice Product, ProductCategory, ProductOrder, OrderItem with order。这些关联定义了哪些实体将生成在哪个微服务中。
  3. 实体之间的关系是否会影响代码生成位置?

    • 实体之间的关系通常不会直接影响代码生成位置。代码生成位置主要由每个实体的 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 &lt;- Ideal would be to have only fronted code
 invoice &lt;- Invoice CRUD code with corresponding ms (with below JDL it is empty)
 order &lt;- Order CRUD code with corresponding ms
 usage &lt;- 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 &quot;11.0.5&quot; 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 * &lt;-- 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 &lt;ENTITIES&gt; with &lt;MICROSERVICE_APP_NAME&gt; relates to the above mentioned entities * section?

3. Is the relationship between entities affects where the code is generated?

答案1

得分: 1

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

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

  3. 不能存在不同微服务之间的实体关系,因为它们存在于不同的数据库中。

英文:
  1. Entities are not generated in a gateway from backend standpoint, only frontend code for these entities is generated

  2. It's used by the gateway to route to correct microservice

  3. There can't be any relationship between entities from different microservices because they reside in distinct databases

huangapple
  • 本文由 发表于 2020年1月3日 18:47:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/59577185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定