1

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?

laci1210
  • 99
  • 1
  • 3

1 Answers1

1
  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

Gaël Marziou
  • 16,028
  • 4
  • 38
  • 49
  • 1. This is also my understanding, but if I associate all etities to some ms, and I give the gateway etities * I am ending up an empty directory where the gateway suppose to be generated, and this what confuses me. In the same time if I leave at least one entitie dissociated, I have the code in the gateway but it also has the backed code for the disassociated entitie. 2. It is clear, but how the etities section in the application section and the "microservice with " working togeher? – laci1210 Jan 03 '20 at 14:00
  • I was unable to reproduce your issue with your JDL file, I saved it as `apps.jdl` and then run `jhipster import-jdl apps.jdl` in an empty directory, I had to change package name because `myApp` is not a valid package but then everything was generated fine. – Gaël Marziou Jan 03 '20 at 16:26
  • Well, I did the same with my home notebook and it is working fine. (Ubuntu) So it seems to be some kind of environment/antivirus/windows policy issue. On my coorporate notebook it is not deterministic at all what service is not generated. (Windows 10 , McAfee) unfortunatelly there is no any error message. – laci1210 Jan 03 '20 at 17:06