jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.58k stars 4.02k forks source link

code of redis cannot be generated for reactive apps #27672

Open flyliu33 opened 1 month ago

flyliu33 commented 1 month ago
Overview of the issue

I try to generate a project based on a official sample jdl file with a slight modify, everything works well but redis. the code of redis cannot be generated properly.

Motivation for or Use Case
Reproduce the error

microservice-ecommerce-reactive.txt

  1. execute command jhipster jdl .\microservice-ecommerce-reactive.jdl
Related issues
Suggest a Fix
JHipster Version(s)

v8.7.1

JHipster configuration
.yo-rc.json file for invoice
{
  "generator-jhipster": {
    "applicationIndex": 2,
    "applicationType": "microservice",
    "authenticationType": "oauth2",
    "baseName": "invoice",
    "buildTool": "maven",
    "entities": [
      "Invoice",
      "Shipment"
    ],
    "jhipsterVersion": "8.7.1",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1729756129000,
    "nativeLanguage": "en",
    "packageName": "com.okta.developer.invoice",
    "prodDatabaseType": "postgresql",
    "reactive": true,
    "serverPort": "8082",
    "serviceDiscoveryType": "consul",
    "skipClient": true,
    "skipUserManagement": true
  }
}
.yo-rc.json file for notification
{
  "generator-jhipster": {
    "applicationIndex": 3,
    "applicationType": "microservice",
    "authenticationType": "oauth2",
    "baseName": "notification",
    "buildTool": "maven",
    "cacheProvider": "no",
    "databaseType": "mongodb",
    "enableHibernateCache": false,
    "entities": [
      "Notification"
    ],
    "jhipsterVersion": "8.7.1",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1729756069000,
    "nativeLanguage": "en",
    "packageName": "com.okta.developer.notification",
    "reactive": true,
    "serverPort": "8083",
    "serviceDiscoveryType": "consul",
    "skipClient": true,
    "skipUserManagement": true
  }
}
.yo-rc.json file for store
{
  "generator-jhipster": {
    "applicationIndex": 0,
    "applicationType": "gateway",
    "applications": {
      "invoice": {
        "applicationIndex": 2,
        "serverPort": "8082"
      },
      "notification": {
        "applicationIndex": 3,
        "serverPort": "8083"
      },
      "product": {
        "applicationIndex": 1,
        "serverPort": "8081"
      }
    },
    "authenticationType": "oauth2",
    "baseName": "store",
    "buildTool": "maven",
    "cacheProvider": "hazelcast",
    "clientFramework": "react",
    "devServerPort": 9060,
    "entities": [
      "Customer",
      "Product",
      "ProductCategory",
      "ProductOrder",
      "OrderItem",
      "Invoice",
      "Shipment",
      "Notification"
    ],
    "jhipsterVersion": "8.7.1",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1729756489000,
    "nativeLanguage": "en",
    "packageName": "com.okta.developer.store",
    "prodDatabaseType": "postgresql",
    "reactive": true,
    "serverPort": 8080,
    "serviceDiscoveryType": "consul",
    "skipUserManagement": true
  }
}
.yo-rc.json file for product
{
  "generator-jhipster": {
    "applicationIndex": 1,
    "applicationType": "microservice",
    "authenticationType": "oauth2",
    "baseName": "product",
    "buildTool": "maven",
    "cacheProvider": "redis",
    "entities": [
      "Product",
      "ProductCategory",
      "ProductOrder",
      "OrderItem"
    ],
    "jhipsterVersion": "8.7.1",
    "languages": [
      "en"
    ],
    "lastLiquibaseTimestamp": 1729756249000,
    "nativeLanguage": "en",
    "packageName": "com.okta.developer.product",
    "prodDatabaseType": "postgresql",
    "reactive": true,
    "serverPort": "8081",
    "serviceDiscoveryType": "consul",
    "skipClient": true,
    "skipUserManagement": true
  }
}
Browsers and Operating System

Edition Windows 11 Pro Version 23H2 Installed on ‎8/‎19/‎2024 OS build 22631.4317 Experience Windows Feature Experience Pack 1000.22700.1041.0

github-actions[bot] commented 1 month ago

JHipster has completed the sample check .yo-rc.json: blank Entities JDL: blank Application: successfully generated Frontend check: skipped Backend check: skipped E2E check: skipped

This check uses jhipster info output from the issue description to generate the sample. Bug report that does not contain this information will be marked as invalid.

mraible commented 4 weeks ago

I tried generating apps from your JDL. I was able to run mvn compile in each project without issues. I did see errors when running mvn verify. What do you mean when you say the Redis code is not generated properly?

flyliu33 commented 4 weeks ago

As usual for a monolithic project created by jhipster, it would create a redis docker compose file and some relevant redis codes in the project while choosing redis as cacheProvider by jhipster command. But while I set redis as cacheProvider for one service in a jdl file, the above attachment as a example, it cannot generate the redis docker compose file and the redis relevant codes. But jhipster jdl can create a kafka docker compose file and the relevant kafka codes while setting kafka as messageBroker in the jdl file. I am not sure if I misunderstood the principle of jhipster, if yes, please explain to me, thanks! image

mraible commented 3 weeks ago

I tried generating a monolith with the CLI and choosing Redis for the cache provider. It creates Docker Compose YAML files just fine. Here's the .yo-rc.json:

{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "redis",
    "buildTool": "maven",
    "cacheProvider": "redis",
    "clientFramework": "angular",
    "clientTestFrameworks": [],
    "clientTheme": "none",
    "creationTimestamp": 1730211299066,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "devServerPort": 4200,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": [],
    "feignClient": null,
    "jhipsterVersion": "8.7.2",
    "languages": ["en"],
    "messageBroker": false,
    "microfrontend": null,
    "microfrontends": [],
    "nativeLanguage": "en",
    "packageName": "com.mycompany.myapp",
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": null,
    "serverSideOptions": [],
    "serviceDiscoveryType": false,
    "syncUserWithIdp": null,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": true
  }
}
$ ll src/main/docker
total 64
-rw-r--r--@ 1 mraible  staff   991B Oct 29 08:15 app.yml
drwxr-xr-x@ 3 mraible  staff    96B Oct 29 08:15 grafana
-rw-r--r--@ 1 mraible  staff   3.1K Oct 29 08:15 jhipster-control-center.yml
drwxr-xr-x@ 3 mraible  staff    96B Oct 29 08:15 jib
-rw-r--r--@ 1 mraible  staff   1.3K Oct 29 08:15 monitoring.yml
-rw-r--r--@ 1 mraible  staff   654B Oct 29 08:15 postgresql.yml
drwxr-xr-x@ 3 mraible  staff    96B Oct 29 08:15 prometheus
drwxr-xr-x@ 4 mraible  staff   128B Oct 29 08:15 redis
-rw-r--r--@ 1 mraible  staff   1.8K Oct 29 08:15 redis-cluster.yml
-rw-r--r--@ 1 mraible  staff   306B Oct 29 08:15 redis.yml
-rw-r--r--@ 1 mraible  staff   286B Oct 29 08:15 services.yml
-rw-r--r--@ 1 mraible  staff   656B Oct 29 08:15 sonar.yml

If I change the JDL to have reactive: true, it forces the Hibernate cache to be false and the following is printed when I generate the app.

INFO! Disabling hibernate cache for cache provider no

This is because the Spring Cache generator disables caching for reactive apps.

We didn't implement caching for reactive apps because it wasn't supported by Spring WebFlux when we implemented it. See https://github.com/jhipster/generator-jhipster/pull/10107.

If you change your app to have reactive: false, it should work.

flyliu33 commented 3 weeks ago

Setting rective: false can work for me. Despite spring webflux doesn't work with hibernate 2nd cache compatibly, there seem to be other alternative caching solutions, like ReactiveRedisTemplate. I am not sure if it's suitable for Jhipster, just my opinion.