我使用的是夸克版本的2.3.0.Final。
我在Controller层中有一个rest端点:
@POST
@Path("/upload")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Uni<Response> uploadFile(@MultipartForm FormData formData) {
return documentService.uploadFile(formData).onItem()
.transform(value -> Response.status(200)
.entity(value)
.build());
}在service层中,代码
public Uni<?> uploadFile(@NonNull FormData formData) throws Exception {
// Call to graphQl client using blocking process - the problem occurs here,
RevisionResponse revisionResponse = entityRepository.createRevision(formData);
// Do upload to s3 using s3 Async
return Uni.createFrom()
.future(
storageProviderFactory.getDefaultStorageProvider().upload(formData)))
.map(storageUploadResponse -> DocumentResponse.builder()
.id(revisionResponse.getId())
.entityMasterId(revisionResponse.getEntityMasterId())
.type(revisionResponse.getType())
.path(formData.getFilePath())
.description(formData.getDescription())
.build());
}下面是我使用的依赖项:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
</dependency>当我运行这个函数时,它在entityRepository.createRevision(formData)中被阻塞(控制台显示graphql请求日志,但实际上,请求甚至没有命中目标graphql端点)
但是,如果我在controller层中添加注释@Blocking,一切都会正常工作。
我也尝试了Uni<RevisionResponse> revisionResponse = entityRepository.createRevision(formData);的Uni响应,但同样的错误发生了。
有没有人遇到这些问题,我有没有为非阻塞进程配置了错误的东西?
谢谢。
发布于 2021-10-17 12:30:55
对于那些面临与我相同的问题的人,我通过用Uni包装阻塞代码来修复它:
Uni<RevisionResponse> revisionResponse = Uni.createForm().item(entityRepository.createRevision(formData));
发布于 2021-10-17 05:12:08
因为您将从方法返回Uni,所以RESTEasy Reactive将在事件循环上运行该方法(有关详细信息,请参阅this )。然而,看起来对entityRepository.createRevision的调用阻塞了IO,这意味着事件循环线程被阻塞了--这是不允许发生的事情。
使用@Blocking注释意味着请求在工作池线程上得到服务,您可以在该线程上阻塞请求。
https://stackoverflow.com/questions/69601166
复制相似问题