背景:我刚刚开始使用Quarkus,正在经历https://quarkus.io/guides/resteasy-reactive
我定义了以下端点:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/greeting/{name}/{count}/{delayInSeconds}")
public Multi<String> greetings(String name, long count, short delayInSeconds) {
return service.greetings(name, delayInSeconds, count);
}
底层service
的细节并不是特别相关,我不认为;它产生CCD_ 2的流。
我在返回的http响应中看到的是未加引号的字符串(无效json(:
curl http://localhost:8080/hello/greeting/neo/4/1
[hello neo - 0,hello neo - 1,hello neo - 2,hello neo - 3]
我尝试将quarkus-resteasy-reactive
的pom.xml
依赖关系替换为quarkus-resteasy-reactive-jackson
,但效果相同(我相信,因为String
已经在这里注册:https://quarkus.io/guides/resteasy-reactive#resource-类型(。
有安全的方法吗?或者只是将Multi
转换为List
,以便jackson可以正确地序列化它?
我将注意上给出的示例https://quarkus.io/guides/getting-started-reactive(官方文件(显示了引用的回复:
$ curl http://localhost:8080/hello/greeting/3/neo
["hello neo - 0", "hello neo - 1", "hello neo - 2"]
更新
这有效地实现了我想要的,尽管我想确认它没有阻塞I/o线程:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/greeting/{name}/{count}/{delayInSeconds}")
// NOTE: conversion to `Uni<List` from `Multi`
public Uni<List<String>> greetings(String name, long count, short delayInSeconds) {
return service.greetings(name, delayInSeconds, count).collect().asList();
}
更新
正如评论中所指出的,这是一个开放的bug:https://github.com/quarkusio/quarkus/issues/18043交割。
正如评论中所指出的,这是一个开放的bug:https://github.com/quarkusio/quarkus/issues/18043交割。