Quarkus-反应性文件下载

时间:2020-03-18 09:12:00

标签: http kotlin download reactive quarkus

有人使用Quarkus举例说明服务器和客户端代码如何使用反应性API通过http下载文件的外观吗?

到目前为止,我尝试返回nio ByteBuffer的流量,但似乎不受支持:

@RegisterRestClient(baseUri = "http://some-page.com")
interface SomeService {

    // same interface for client and server
    @GET
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    @Path("/somePath")
    fun downloadFile(): reactor.core.publisher.Flux<java.nio.ByteBuffer>
}

尝试在服务器端返回磁通量会导致以下异常:

ERROR: RESTEASY002005: Failed executing GET /somePath
org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: kotlinx.coroutines.reactor.FlowAsFlux of media type: application/octet-stream
    at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$3(ServerResponseWriter.java:124)
    at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:403)
    at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:251)
    ...

1 个答案:

答案 0 :(得分:2)

Here是一个如何使用Smallrye Mutiny开始反应文件下载的示例。主要功能是getFile

float v = CrossPlatformInputManager.GetAxis("Horizontal") * -1;
float h = CrossPlatformInputManager.GetAxis("Vertical") * -1;

您可以使用@GET @Path("/f/{fileName}") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Uni<Response> getFile(@PathParam String fileName) { File nf = new File(fileName); log.info("file:" + nf.exists()); ResponseBuilder response = Response.ok((Object) nf); response.header("Content-Disposition", "attachment;filename=" + nf); Uni<Response> re = Uni.createFrom().item(response.build()); return re; } 在本地进行测试,然后转到该URL以查看其中有什么文件http://localhost:8080/hello/list/test,然后您可以调用该URL以开始下载http://localhost:8080/hello/f/reactive-file-download-dev.jar

我没有检查过助焊剂(看起来像是更多的春季,然后是夸克),请随时分享您的想法。我只是在学习和回答/共享。

相关问题