【问题标题】:Reactor core with JAX RS带有 JAX RS 的反应堆核心
【发布时间】:2022-10-14 22:51:53
【问题描述】:

我正在使用生成 JSON 元素的 JAX-RS 构建 REST API。除此之外,我还想添加带有 Reactor 核心的反应式 REST API。 这里的代码:

@Path("v1")
@Component
@Transactional(readOnly = true)
public class RestBatchComponent {

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    @Path("test")
    public Flux<Long> getJsonImplicitListStreamingAsync() {
        Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
                Long>of(0L, 1L), (state, sink) -> {
            if (state.getT1() < 0) {sink.complete();} else {sink.next(state.getT1());}
            return Tuples.of(state.getT2(), state.getT1() + state.getT2());
        });
        CountDownLatch latch = new CountDownLatch(1);
        fibonacciGenerator
                .delayElements(Duration.ofMillis(100L))
                .sample(Duration.ofSeconds(1))
                .subscribe();
        //.subscribe(x -> System.out.println(x), e -> latch.countDown(), () -> latch.countDown());*/
        return fibonacciGenerator;
    }

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    @Path("test1")
    public List<String> getAll() {
        List<String> messages = Arrays.asList("Hello", "World!", "How", "Are", "You");
        return messages;
    } 
}

运行 Tomcat 9 服务器和测试 API 调用时

测试 1: http://localhost:8080/as/v1/test ,给出

{
"scanAvailable": true,
"prefetch": -1
}

获取 JSON 流缺少什么?

测试 2:http://localhost:8080/as/v1/test1,给出

[
"Hello",
"World!",
"How",
"Are",
"You"
]

怎么了 ?是否有关于如何将 JAX RS REST API 与反应堆核心相结合的教程?

【问题讨论】:

    标签: java json jax-rs project-reactor


    【解决方案1】:

    你设法让它工作吗?

    谢谢,

    【讨论】:

    猜你喜欢
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 2011-11-16
    • 2014-04-15
    • 2018-01-31
    相关资源
    最近更新 更多