在 Project Reactor 中识别反应链中字节数组的来源
Identifying the origin of byte arrays in a reactive chain in Project Reactor
我正在从 3 张灰度图像构建彩色图像。我使用 rsocket 为每个色带发出 3 个单独(并行)请求,其中 returns a Mono<byte[]>
。我需要将所有 3 字节数组收集为一个列表,以便我可以正确构建图像。但是,我对如何在下一个反应操作中识别字节数组属于哪个波段感到困惑。
下面是一些示例代码:
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); //???
}
我创建了一个包装器 class 来保存原始请求、字节数组和 band 标识符,这样我就可以在每个操作中传递所有对象,但是因为我的 rsocket 客户端的响应是 Mono,我只能通过在 map 或 flatMap 中调用它来具体化(可能是错误的术语)字节数组,此时我无法访问我的包装器 class 并且我不确定字节数组属于哪个波段到.
我可以通过不在并行请求中调用客户端来解决这个问题吗?我能保证项目将按照我在 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;
//
})
我正在从 3 张灰度图像构建彩色图像。我使用 rsocket 为每个色带发出 3 个单独(并行)请求,其中 returns a Mono<byte[]>
。我需要将所有 3 字节数组收集为一个列表,以便我可以正确构建图像。但是,我对如何在下一个反应操作中识别字节数组属于哪个波段感到困惑。
下面是一些示例代码:
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); //???
}
我创建了一个包装器 class 来保存原始请求、字节数组和 band 标识符,这样我就可以在每个操作中传递所有对象,但是因为我的 rsocket 客户端的响应是 Mono,我只能通过在 map 或 flatMap 中调用它来具体化(可能是错误的术语)字节数组,此时我无法访问我的包装器 class 并且我不确定字节数组属于哪个波段到.
我可以通过不在并行请求中调用客户端来解决这个问题吗?我能保证项目将按照我在 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;
//
})