Java Code Examples for reactor.core.publisher.Flux#doOnError()
The following examples show how to use
reactor.core.publisher.Flux#doOnError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactorHttpRpcClient.java From etherjar with Apache License 2.0 | 6 votes |
@Override public Flux<RpcCallResponse> execute(ReactorBatch batch) { BatchCallContext<ReactorBatch.ReactorBatchItem> context = new BatchCallContext<>(); Flux<RpcCallResponse> result = batch.getItems() .doOnNext(context::add) .thenMany(transport.execute(batch.getItems(), context)) .onErrorResume(ConnectException.class, ReactorHandlers.catchConnectException()) ; FailedBatchProcessor failedBatchProcessor = this.getFailedBatchProcessor(); if (failedBatchProcessor != null) { Function<RpcException, Publisher<RpcCallResponse>> fallback = failedBatchProcessor.createFallback(batch); if (fallback != null) { result = result.onErrorResume(RpcException.class, fallback); } } result = postProcess(batch, context, result); result = result.doOnError((t) -> System.err.println("HTTP Error " + t.getClass() + ": " + t.getMessage())); return result.share(); }
Example 2
Source File: FooService.java From tutorials with MIT License | 5 votes |
public void processFoo(Flux<Foo> flux) { flux = FooNameHelper.concatFooName(flux); flux = FooNameHelper.substringFooName(flux); flux = flux.log(); flux = FooReporter.reportResult(flux); flux = flux.doOnError(error -> { logger.error("The following error happened on processFoo method!", error); }); flux.subscribe(); }
Example 3
Source File: FooService.java From tutorials with MIT License | 5 votes |
public void processUsingApproachOneWithErrorHandling(Flux<Foo> flux) { logger.info("starting approach one w error handling!"); flux = concatAndSubstringFooName(flux); flux = concatAndSubstringFooName(flux); flux = substringFooName(flux); flux = processFooReducingQuantity(flux); flux = processFooReducingQuantity(flux); flux = processFooReducingQuantity(flux); flux = reportResult(flux, "ONE w/ EH"); flux = flux.doOnError(error -> { logger.error("Approach 1 with Error Handling failed!", error); }); flux.subscribe(); }
Example 4
Source File: FooService.java From tutorials with MIT License | 5 votes |
public void processUsingApproachThree(Flux<Foo> flux) { logger.info("starting approach three!"); flux = concatAndSubstringFooName(flux); flux = reportResult(flux, "THREE"); flux = flux.doOnError(error -> { logger.error("Approach 3 failed!", error); }); flux.subscribe(); }
Example 5
Source File: FooService.java From tutorials with MIT License | 5 votes |
public void processUsingApproachFourWithInitialCheckpoint(Flux<Foo> flux) { logger.info("starting approach four!"); flux = concatAndSubstringFooName(flux); flux = flux.checkpoint("CHECKPOINT 1", true); flux = concatAndSubstringFooName(flux); flux = divideFooQuantity(flux); flux = reportResult(flux, "FOUR"); flux = flux.doOnError(error -> { logger.error("Approach 4-2 failed!", error); }); flux.subscribe(); }
Example 6
Source File: ReactorEmeraldClient.java From etherjar with Apache License 2.0 | 4 votes |
@Override public Flux<RpcCallResponse> execute(ReactorBatch batch) { BlockchainOuterClass.NativeCallRequest.Builder requestBuilder = BlockchainOuterClass.NativeCallRequest.newBuilder(); requestBuilder.setChain(chainRef); if (selector != null) { requestBuilder.setSelector(selector); } BatchCallContext<ReactorBatch.ReactorBatchItem> context = new BatchCallContext<>(); Mono<BlockchainOuterClass.NativeCallRequest> request = batch.getItems() .doOnNext(context::add) .map(this::asNative) .reduce(requestBuilder, BlockchainOuterClass.NativeCallRequest.Builder::addItems) .map(BlockchainOuterClass.NativeCallRequest.Builder::build); Flux<RpcCallResponse> result = stub.nativeCall(request) .flatMap((item) -> { RpcCall<?, ?> call = null; try { call = context.getCall(item.getId()); } catch (Exception e) { System.err.println("Invalid id returned from upstream: " + item.getId()); } return read(item, call); }) .onErrorResume(StatusRuntimeException.class, (e) -> { if (e.getStatus().getCode() == Status.Code.CANCELLED) { return Mono.empty(); } return Mono.error(new RpcException( RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR, "gRPC connection error. Status: " + e.getStatus(), null, e )); }) .map(responseJsonConverter.forContext(context)); FailedBatchProcessor failedBatchProcessor = this.getFailedBatchProcessor(); if (failedBatchProcessor != null) { Function<RpcException, Publisher<RpcCallResponse>> fallback = failedBatchProcessor.createFallback(batch); if (fallback != null) { result = result.onErrorResume(RpcException.class, fallback); } } result = result.doOnError((t) -> System.err.println("Client error " + t.getClass() + ": " + t.getMessage())); result = postProcess(batch, context, result); return result.share(); }