gpt4 book ai didi

java - 识别 Project Reactor 中 react 链中字节数组的来源

转载 作者:行者123 更新时间:2023-12-02 01:50:34 25 4
gpt4 key购买 nike

我正在从 3 个灰度图像构建彩色图像。我使用 rsocket 对每个色带发出 3 个单独(并行)请求,该请求返回 Mono<byte[]> 。我需要将所有 3 个字节数组收集为一个列表,以便我可以正确构建图像。但是,我对如何在下一个 react 操作中识别字节数组属于哪个带感到困惑。

这里是一些示例代码:

 return Flux.just(redRequest, blueRequest, greenRequest)
.parallel()
.flatMap(client::getBytes) // calls the remote service to get the bytes for the given color band
.sequential()
.collectList()
.map(response -> {
byte[] redBytes = response.get(0); //???
}

我创建了一个包装类来保存原始请求、字节数组和带标识符,这样我就可以在每个操作中传递所有对象,但是因为我的 rsocket 客户端的响应是 Mono,所以我只能实现(可能错误的术语)通过在映射或平面映射中调用字节数组,此时我无法访问我的包装类,并且我不确定字节数组属于哪个带。

我可以通过不在并行请求中调用客户端来解决此问题吗?我能否保证项目将按照我在 Flux.just() 中定义的顺序在链中传播? 。

基本上在最后一张图中,我只是想知道哪个字节数组属于哪个颜色带。

最佳答案

使用颜色字段将每个请求包装在对象中,并更改发送这些请求的管道的 flatMap 部分:

Flux.just(
new Request(redRequest, RED),
new Request(blueRequest, BLUE),
new Request(greenRequest, GREEN)
)
.parallel()
.flatMap(request ->
client.getBytes(request)
.map(response -> new Response(response.get(0), request.color))
)
.sequential()
.collectList()
.map(response -> {
byte[] redBytes = response.bytes;
Color color = response.color;
//
})

关于java - 识别 Project Reactor 中 react 链中字节数组的来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53036191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com