java - 在 QUARKUS 中使用 Reactive RestEasy 和 GraphQlClient 时出现线程阻塞问题
问题描述
我正在使用 quarkus 版本2.3.0.Final
。
我在Controller
图层中有一个休息端点:
@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端点)
@Blocking
但是,如果我在图层中添加注释controller
,一切都会按预期工作。
我也尝试了Uni
响应,Uni<RevisionResponse> revisionResponse = entityRepository.createRevision(formData);
但发生了同样的错误。
有没有人遇到这些问题,我是否为非阻塞处理配置了错误?
谢谢你。
解决方案
对于那些对我有同样问题的人,我通过用 Uni 包装阻塞代码来解决它:
Uni<RevisionResponse> revisionResponse = Uni.createForm().item(entityRepository.createRevision(formData));
推荐阅读
- javascript - 微软语音识别+nodejs
- javascript - MongoDB网站中的Css变换效果
- sqlite - 在查询中列出一周中的所有天
- ios - iOS 13:Swift - “以编程方式设置应用程序根视图控制器”不起作用
- android - 如何在不是 Activity 的简单类中设置位置
- ssis - SSIS 项目无法在自托管代理上构建
- spring-el - 如何让 Watson 助手重复上次响应?
- android - 浏览器无法使用深度链接从浏览器打开应用
- symfony - 没有为类 App\Entity\Category 定义实体管理器
- java - 绑定访问 YAML 文件时抛出 NullPointPointer