我想创建一个报告,将所有失败的上传(仅限id)保存到列表中。我的例子只保存最后一项。我错过了什么吗?应该过滤掉所有成功上传的内容。
服务:
Flux<Entity> fluxMerge = Flux.merge(fluxA, fluxB);
Mono<List<Long>> errorIds = fluxMerge.
.onErrorResume(MyException.class, err -> Mono.just(err.getEntity()))
.map(Entity::getId)
.collectList();
RestService:
return Mono.create(monoSink ->
exchange.addCallback(result -> monoSink.success(result.getBody()),
err -> monoSink.error(new MyException(entity))));
提前致谢!
答案 0 :(得分:2)
Reactivex documentaion http://reactivex.io/documentation/operators/merge.html
说来自任何合并的助焊剂的错误将终止合并的助焊剂。这就是onErrorResume
仅处理第一个错误的原因。
我可以建议2种方法
添加&#39; onErrorResume&#39;合并之前处理每个助焊剂的处理程序
Flux<Entity> fluxMerge = Flux.merge(
fluxA.onErrorResume(MyException.class, err -> Mono.just(err.getEntity())),
fluxB.onErrorResume(MyException.class, err -> Mono.just(err.getEntity())));
Mono<List<Long>> errorIds = fluxMerge.map(Entity::getId).collectList();
模型上传错误作为流量中的消息,仅对仅在休息服务上产生503的关键问题使用流量错误
return Mono.create(monoSink -> exchange.addCallback(
result -> monoSink.success(new Success(result.getBody())),
err -> monoSink.success(new UploadError(entity))));
Flux<Result> fluxMerge = Flux.merge(fluxA, fluxB);
Mono<List<Long>> errorIds = fluxMerge.filter(Result::isError).map(Result::entity).map(Entity::getId).collectList()
interface Result{
Boolean isError();
Entity entity();
}
class Success implements Result { ... }
class UploadError implements Result { ... }