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.54k stars 4.02k forks source link

Problem with asynchronous REST API #8363

Closed arabbani closed 6 years ago

arabbani commented 6 years ago
Overview of the issue

I have a rest controller that returns Callable. @GetMapping("/fb-roles") @Timed public Callable<List<FbRole>> getAllFbRoles() { log.debug("REST request to get all FbRoles"); return (() -> { return fbRoleRepository.findAll(); }); }

JHipster configures a ThreadPoolTaskExecutor as following: ` @Configuration @EnableAsync @EnableScheduling public class AsyncConfiguration implements AsyncConfigurer {

private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);

private final JHipsterProperties jHipsterProperties;

public AsyncConfiguration(JHipsterProperties jHipsterProperties) {
    this.jHipsterProperties = jHipsterProperties;
}

@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("fb-quiz-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}

@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
    return new SimpleAsyncUncaughtExceptionHandler();
}

} `

But while accessing the api server is producing the following warning 2018-09-19 00:43:58.434 WARN 10104 --- [ XNIO-2 task-28] o.s.w.c.request.async.WebAsyncManager : !!! An Executor is required to handle java.util.concurrent.Callable return values. Please, configure a TaskExecutor in the MVC config under "async support". The SimpleAsyncTaskExecutor currently in use is not suitable under load.

Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)

JHipster v5.3.1

JHipster configuration
fb-quiz@0.0.0 D:\Projects\arif\fb-quiz
`-- generator-jhipster@5.3.1
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.creatives.apsstr"
    },
    "jhipsterVersion": "5.3.1",
    "applicationType": "monolith",
    "baseName": "FbQuiz",
    "packageName": "com.creatives.apsstr",
    "packageFolder": "com/creatives/apsstr",
    "serverPort": "8080",
    "authenticationType": "session",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "rememberMeKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "npm",
    "testFrameworks": [],
    "jhiPrefix": "apsstr",
    "enableTranslation": false
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
Environment and Tools

java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

git version 2.14.1.windows.1

node: v8.11.3

npm: 6.1.0

yarn: 1.7.0

Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
Blackdread commented 6 years ago

I think you need to check/learn Reactive Spring (webflux) and see how it works

arabbani commented 6 years ago

For now, I don't wnat to migrate to webflux. For now, i want to continue with spring mvc

jdubois commented 6 years ago

I'm sorry but this is not a bug, just a configuration you should do on Spring Boot - please have a look at the Spring Boot documentation, or ask a question on StackOverflow if that is not enough. We do not provide this configuration out-of-the-box, as this is not a common requirement. We do indeed some similar things with a sync controller that calls an async service method, but we don't have async controllers by default.

gmarziou commented 6 years ago

https://stackoverflow.com/questions/52397752/asynchronous-rest-api-generating-warning

jdubois commented 6 years ago

Then @arabbani it's not really nice to spam us, per the guidelines you should create one ticket if that's a bug or one question if that's a question. Please don't spam us.

arabbani commented 6 years ago

Sorry @jdubois . I thought it's a bug. So sorry for the inconvenience

jdubois commented 6 years ago

No problem @arabbani you're really not the only one doing this :-) I'm just trying not to have the same question/issue twice, as we follow both channels, and that makes extra work. Also, if other people have the same issue, they are lost.